- Code: Select all
class Redo(sublime_plugin.EventListener):
pending = 0
def on_modified(self, view):
if self.pending == 1:
return
self.pending = 1
try:
edit = view.begin_edit()
view.run_command('redo')
finally:
view.end_edit(edit)
self.pending = 0
Save this code as a plugin, edit a buffer, and hit undo twice.
I ran into this because I'm trying to add to a closed edit—i.e., when the user types something, I want to modify the buffer, but I want to do it in such a way that hitting undo once will undo both my changes and their changes. I tried to call "undo", and then start an edit and call "redo" and make my changes before closing the edit, and that's when I ran into this issue.