Key is inserted when running command
In Kakoune you can define custom command and access them with the , key. Could it be possible to implement the same thing in dance so that we can map custom commands ?
For example, by adding
"custom": {
"items":{
"w": {
"text": "hard wrap selection",
"command": "rewrap.rewrapComment"
},
"c": {
"text": "comment selection",
"command": "editor.action.commentLine"
},
}
},
in the settings, next to the "goto" definitions, we could access the rewrap.rewrapComment function by pressing , (which will toggle a small menu, like g for goto) and then w
I'm basically struggling with Dance because I find it hard to add custom commands : if I declare a new keybinding on the c key in VSCode, with a When dance.mode == "normal", when I press c in normal mode, it calls the function AND prints a c on the screen, even if I am in normal mode... So I thought that having a controlled keybind to map custom functions, it could be nice...
Hey there! The way you created a menu is correct, and the way to add commands is indeed to add VS Code keybindings. However, the fact that c is printed on the screen as well is unexpected.
I just tested this code locally and it only opens up the menu without printing anything.
{
"key": "c",
"command": "dance.openMenu",
"args": { "menu": "test" },
"when": "dance.mode == 'normal'"
}
Similarly, invoking a command via the menu executes the command without printing the key. I'm not sure what's wrong on your end.
Hi ! Thanks a lot for your answer !
I didn't know I could just call dance.openMenu with the menu arg to open a custom menu, thanks for pointing it out ! I will build my custom menu with this.
For the strange conflicts, I checked a bit more precisely and turns out the problem was with conflicting keys and only with specific functions : it was all right with dance.openMenu, but if I replaced it with editor.action.commentLine, when in Insert mode, pressing c printed a C and commented the line . When I removed the default c binding of Dance, the problem disappeared, so it seems it came from the conflict. But it is still strange because the default binding only triggers when in Normal mode, so I don't understand why conflicting bindings in Normal mode caused the key to trigger the function in Insert mode.
No problem... I somehow haven't taken the time to update the docs to reflect this yet, so one would need to dig through the issues to find out that this is possible.
Unfortunately I was still unable to reproduce. Are you also trying with the key c, or is it possible that some international keyboard voodoo is somehow messing up with the input? Your best shot at determining exactly where the problem comes from is by debugging Dance (clone the repository, open it in VS Code, run "Debug extension" and put a breakpoint in the command body).
After some tests, it seems that even without the conflicting dance keys, the problem is still here. And with the debugging process that you described, I saw all the keys Dance intercepted, but when pressing c while in Insert mode, it commented the line and added a c character, but Dance intercepted nothing.
So it looks like the problem comes from the when section of the command, VSCode calling the command even if dance.mode == 'normal' should be false
And yeah, I'm not using a standard US keyboard, and I know VScode handles pretty badly (to stay polite) non-US keyboards and symbols... So it may come from this