Sublime Forum

Detect it's whether a Undo or a Redo command in on_modified?

#1

I want to make my plugin transparent to end user like this:

def on_modified(self, view):
    command = view.command_history(0)
    if command[0] == 'my_command':
        if _IT_IS_UNDO_:
            view.run_command('undo')
        elif _IT_IS_REDO_:
            view.run_command('redo')

But the Undo and Redo commands don’t appear in command_history(), so how can I know is it a undo or redo command in on_modified?

Thanks for helping.

0 Likes

#2

In my Elastic Tabstops plugin (github.com/SublimeText/ElasticTabstops) I actually overrode undo and redo because I couldn’t figure out how else to do it. This was before view.command_history existed, though, so there may be a better way now. Let us know if you get something workable!

0 Likes