replit / codemirror-vim

Vim keybindings for CM6
https://www.npmjs.com/package/@replit/codemirror-vim
MIT License
300 stars 29 forks source link

Keybindings with Option key on Mac are not working #193

Open dpecos opened 4 days ago

dpecos commented 4 days ago

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.

nightwing commented 3 days ago

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.

dpecos commented 2 days ago

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!

nightwing commented 1 day ago

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.