johtela / vscode-modaledit

Configurable Modal Editing in VS Code
https://johtela.github.io/vscode-modaledit/docs/README.html
Other
89 stars 8 forks source link

Feature request: stateful commands? #27

Open zhaojiangbin opened 2 years ago

zhaojiangbin commented 2 years ago

First of all, thanks for this wonderful extension.

Say I want to define a command for the 'v' key, that, depending on how many time I press the key in a row, the command shows the current line at the top, center, bottom of the editor pane, respectively.

For example, on the first press of 'v', the command brings the current line to the top. If I press the 'v' key again, it brings the current line to the center. Then on the third press, the line is at the bottom. Pressing the key again, the line goes to the top, so on and so forth.

Right now I have to define three commands like below:

        "v": {
            "help": "Show current line at [C]enter/[T]op/[B]ottom"
            "c": {
                "command": "revealLine",
                "args": "{ lineNumber: __line, at: 'center' }"
            },
            "t": {
                "command": "revealLine",
                "args": "{ lineNumber: __line, at: 'top' }"
            },
            "b": {
                "command": "revealLine",
                "args": "{ lineNumber: __line, at: 'bottom' }"
            }
        },

But it would be better if I can just keep pressing the same key, 'v', to cycle through the three positions.

I'd imagine for such commands to work they will need to carry a state hence the issue's subject "stateful commands".