Open tomKPZ opened 3 years ago
It's probably possible to implement this, given that it's possible to record actions and replay them (though it's hard, IMO, which is why .
often fails spectacularly in Dance). I haven't implemented it yet, though.
Side note: I couldn't reproduce with 5+idance<esc>
in Kakoune.
Thanks for considering this!
In Kakoune, duplicating selections with +
was added recently, (Feb 14, 2021) https://github.com/mawww/kakoune/commit/fa3aa3c1a
You need to use the latest Kakoune (2021.08.28) for this feature.
Ah, I see. Indeed, VS Code will automatically merge overlapping selections, which is outside of the control of Dance. In theory we could emulate it with listeners to document changes and an internal state, but I guess it would be a pretty intrusive feature for a pretty specific usage.
With 03fe2cc66bf11b90ca991cced1f9390266645dc3, you can achieve something similar-ish (at least for the example you gave) with the following key binding:
{
"key": "shift+= i",
"command": "dance.run",
"args": {
"input": [
"const key = (await keypress()).repeat(repetitions);",
"await replace(() => key.repeat(repetitions));",
"Selections.set(Selections.selectWithin(/./g).map((s) => Selections.empty(s.active)));",
"await toMode('insert');",
],
},
"when": "editorTextFocus && dance.mode == 'normal'",
},
It adds a keybinding shift+= i
(+
followed by i
) which executes a command that asks for a key, then inserts it with the current count, selects the end of each inserted character, and then switches to insert. 03fe2cc66bf11b90ca991cced1f9390266645dc3 is required because repetitions
was not defined previously in dance.run
code.
Currently the best way to type out something like
dancedancedancedance
isidance<esc>3.
. However it would be ideal to achieve this in a more direct way. Vim allows5idance<esc>
and kakoune allows5+idance<esc>
, however I'm not sure if it's possible to implement the kakoune style given the limitations of VSCode.