Home Download Buy Blog Forum Support

Partial Undo

Partial Undo

Postby Oleg on Thu Nov 22, 2012 11:03 am

Hello,

I have the simple plugin, as following:

Code: Select all
import sublime, sublime_plugin

class Simple(sublime_plugin.TextCommand):
         ...
         # undo point 1
         edit_insert = self.view.begin_edit()
         ... insert something ...
         self.view.end_edit(edit_insert)

         ...

         # undo point 2
         edit_insert = self.view.begin_edit()
         ... insert something else ...
         self.view.end_edit(edit_insert)


My expectation is that this plugin will create TWO different undo "points". Unfortunatelly Ctrl+Z undoes all changes performed by plugin. Is there any way to create two undo points inside the single command?
Oleg
 
Posts: 2
Joined: Thu Nov 22, 2012 10:57 am

Re: Partial Undo

Postby bizoo on Thu Nov 22, 2012 12:45 pm

It's probably because TextCommand as already an implicit edit that you receive in argument.
Inside undos are regrouped in this global undo.

You can use a WindowCommand to achieve what you want:
Code: Select all
import sublime, sublime_plugin

class SimpleCommand(sublime_plugin.WindowCommand):
    def run(self):
        # undo point 1
        edit_insert = self.window.active_view().begin_edit()
        self.window.active_view().insert(edit_insert, 0, "Hello, World!")
        self.window.active_view().end_edit(edit_insert)

        # undo point 2
        edit_insert = self.window.active_view().begin_edit()
        self.window.active_view().insert(edit_insert, 0, "Hello, World!")
        self.window.active_view().end_edit(edit_insert)
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Partial Undo

Postby Oleg on Thu Nov 22, 2012 12:56 pm

At first glance this is what I needed. Thnx a lot
Oleg
 
Posts: 2
Joined: Thu Nov 22, 2012 10:57 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 9 guests