Sublime Forum

Deselect and save / restore cursor position

#1

I am trying to bind a key to perform these with ChainOfCommand package, it works great. However, I like to see if I can save the cursor position, unselect and restore cursor position at the end. What are the commands should I call ? Thanks!

[
    {
        "keys": ["ctrl+alt+f"],
        "command": "chain",
        "args": {
            "commands": [
                ["save_cursor_position"],
                ["select_all"],
                ["unindent"],
                ["reindent"],
                ["unselect"],
                ["restore_cursor_position"]
            ]
        }
    }
]
0 Likes

#2

If you install MultiEditUtils you can use command selection_fields. This supports to add the current selection as a “field” and you can afterwards pop these “fields” back as selections.

Using this you can change your keybinding:

{
    "keys": ["ctrl+alt+f"],
    "command": "chain",
    "args": {
        "commands": [
            ["selection_fields", {"mode": "add"}],
            ["select_all"],
            ["unindent"],
            ["reindent"],
            ["selection_fields", {"mode": "pop", "only_other": true}]
        ]
    }
}
1 Like

#3

This works perfect. Thanks!

0 Likes