jisaacks / ChainOfCommand

Sublime text plugin to run a chain of commands
67 stars 4 forks source link

How to undo the whole chain? #11

Open saveman71 opened 5 years ago

saveman71 commented 5 years ago

Hello! Thanks for the great package.

Given the following:

  {
     "keys": ["ctrl+shift+up"],
     "command": "chain",
     "args": {
       "commands": [
         ["swap_line_up"],
         ["reindent", {"single_line": true}]
       ],
     },
   },
  {
    "keys": ["ctrl+shift+down"],
    "command": "chain",
    "args": {
      "commands": [
        ["swap_line_down"],
        ["reindent", {"single_line": true}]
      ],
    },
  },

I'd love sublime to understand that one "shortcut" should be undoable "as a whole action". Currently to undo the whole chain, i have to hit ctrl+z multiple times (sometimes only once if the "reindent" action didn't do anything.

Is anyone aware of any solution to make Sublime Text understand I want to wrap this whole "chain" (and whatever it does to the buffer) as one single atomic action?

mitranim commented 4 years ago

Had the same problem. A discussion in the ST Discord revealed that this can be fixed by converting the plugin from WindowCommand to TextCommand:

import sublime_plugin

class chain(sublime_plugin.TextCommand):
    def run(self, edit, commands):
        for command in commands:
            self.view.window().run_command(*command)

You can make a small local plugin, or use PackageResourceViewer to unpack CoC and edit it. If this works well, this change should probably be made in CoC so that everyone can benefit, but I'm still evaluating this.

mitranim commented 4 years ago

Also, judging by the source, Multicommand uses TextCommand and should be undoable all at once. Haven't tried it yet.

saveman71 commented 4 years ago

Yaay, I had these shortcuts commented for 1 year and a half now and finally I can use it! Thanks!