codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

Keybindings with Option key on Mac are not working

Open dpecos opened this issue 1 year ago • 3 comments

I've been having this issue where if I define a custom key binding for an action (i.e Option+v) that uses the Option key on mac (the example would translate to <A-v>, the key binding does not work.

After having a look to the code, I've found this is the cause of the issue: https://github.com/replit/codemirror-vim/blob/160a7fdbf25f17eede87e75e04b3874b73ac8a41/src/vim.js#L1149-L1154

The combination gets transformed in order to support international characters, but it breaks this kind of key combinations.

One workaround, which is not ideal, specially for potential side effects, is to make CodeMirror believe you're not actually on a Mac:

CodeMirror.isMac = false;

with this, the keybinding works as expected, but of course, I'm not able to write international characters anymore.

dpecos avatar Oct 22 '24 10:10 dpecos

Currently we are following macvim behavior on mac. That is, you can do :map å ihello and then pressing Option-A inserts å and gets expanded to ihello. There seems to be a bug with handling of Option+v which seems to be captured by visual mode, but would it be ok if Option+v worked the same as Option+a? If no, with which version of vim are you comparing, as i could not get <A-v> style mappings to work in terminal either.

nightwing avatar Oct 23 '24 21:10 nightwing

I wasn't comparing with vim/neovim, but with codemirror with vim keymap running on linux box.

What I didn't think about was to check on actual vim, and you're right, the behaviour between linux and mac is different: on linux a map using <A-a> works, but not on mac, where you have to use å instead.

So I guess if consistency with the vim implementation is what you're looking for, which makes sense, this is not a bug.

Feel free to close the issue, I leave it open just to hear your opinion.

Thx a lot!

dpecos avatar Oct 24 '24 08:10 dpecos

Attached pull request allows to use <A-v> mapping similar to linux, as long as user does not add mapping for unicode character inserted by <A-v>. You can test it on https://raw.githack.com/replit/codemirror-vim/mac-A-mapping/dev/web-demo.html Sadly there is no way to detect keyboard layout in order to know which key would have appeared if alt had not been pressed, so v is interpretted based on event.code which is based on key value in qwerty layout.

nightwing avatar Oct 25 '24 22:10 nightwing

Thx a lot for the PR, I've tested and it works great, but I've also noticed something a little bit off: the keybinding gets detected both in normal and insert modes, but when in insert mode, it exits back to normal mode, not sure that's the expected behaviour.

dpecos avatar Oct 29 '24 13:10 dpecos

Thank you for testing. The demo has a code to toggle vim with alt-v keybinding, for testing, this won't happen in normal usage.

nightwing avatar Nov 04 '24 17:11 nightwing