Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keybindings with Option key on Mac are not working #193

Open
dpecos opened this issue Oct 22, 2024 · 5 comments · May be fixed by #194
Open

Keybindings with Option key on Mac are not working #193

dpecos opened this issue Oct 22, 2024 · 5 comments · May be fixed by #194

Comments

@dpecos
Copy link

dpecos commented Oct 22, 2024

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:

codemirror-vim/src/vim.js

Lines 1149 to 1154 in 160a7fd

// on mac many characters are entered as option- combos
// (e.g. on swiss keyboard { is option-8)
// so we ignore lonely A- modifier for keypress event on mac
if (CodeMirror.isMac && e.altKey && !e.metaKey && !e.ctrlKey) {
name = name.slice(2);
}

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
Copy link
Collaborator

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
Copy link
Author

dpecos commented Oct 24, 2024

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 nightwing linked a pull request Oct 25, 2024 that will close this issue
@nightwing
Copy link
Collaborator

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.

@dpecos
Copy link
Author

dpecos commented Oct 29, 2024

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.

@nightwing
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants