Sublime Forum

Command not showing up in view.command_history


I have a command that needs to know if it was the last executed.

Unfortunately, view.command_history seems to not be reliable… it doesn’t want to log this particular command of mine, though it logs other commands I’ve created, and I can’t tell what distinguishes the two.

Here is some sample code:

class MoveByBinarySearchCommand(sublime_plugin.TextCommand):
    def run(self, edit, horizontal=True, forward=True):
        last = self.view.command_history(0)[0]
        print("last command:", last)

No matter how many times I invoke the above command, the last command logged is never “move_by_binary_search”, though the print statement is occuring.

Does a command have to modify the view in some way before it is logged into the command history?



The documentation for view.command_history() says that it gets the history entry from the undo/redo stack and I think only commands that modify things can be undone, so that may indeed be the issue for this command.

From some quick experimentation, commands like move appear in the command history and it’s modifying the cursor location (selection) so even doing that should make the command appear, I think.

1 Like