Sublime Forum

Partial Undo

#1

Hello,

I have the simple plugin, as following:

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?

0 Likes

#2

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]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)[/code]
0 Likes

#3

At first glance this is what I needed. Thnx a lot

0 Likes