-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fix some keyboard shortcuts for layouts with AltGr #1031
Conversation
In many keyboard layouts, such as German, French and Swedish, some characters have to be typed using the AltGr key. If such a key is the non-first key of a VMP keyboard shortcut _sequence,_ the sequence fails to trigger. This is because Atom receive an 'altgraph' key press inbetween. For example, the shortcut `g ~` is seen as `g altgraph ~`. 'altgraph' seems to be handled just like any other key, so just like `g a ~` does not exist, neither does `g altgraph ~`. This commit duplicates shortcuts containing problematic AltGr keys. For example, in addition to the `g ~` shortcut I've added `g altgraph ~`. The keys I did this for are: `~ $ | [ ] { }`. Fixes t9md#661.
This solution works for me, and it was easy to implement. However, if users add their own shortcuts, they might be confused why some of them don’t work. For example: 'i space {': 'vim-mode-plus:inner-curly-bracket-allow-forwarding'
# should be:
'i space altgraph {': 'vim-mode-plus:inner-curly-bracket-allow-forwarding' How come 'shift' does not have this problem? If I open the “Key Binding Resolver” in Atom (ctrl+.) and press a shift key, it does say that 'shift' has been pressed. This is true for all modifiers. Does VMP special-case shift somewhere – so we could special-case 'altgraph' too? Or does Atom special-case shift? It would be awesome if we didn’t have to specify 'altgraph' in our keymaps, but I understand if there’s nothing VMP can do about this. |
@lydell Do you have any keyboard layout packages installed like I am interested to fix this issue in Atom but I don't have any problems with the reported commands on a Swedish layout. Atom by default does not resolve any keystroke to |
I can reproduce it on Ubuntu 17.10 with the standard 'se' keyboard layout in a clean Atom profile with only VMP installed.
But as you can see I haven’t installed Atom 1.24 yet so I guess I should try that... EDIT: Installed Atom 1.24.0. Made no difference. |
@lydell That's really interesting. What do you see in the keybinding resolver when typing this keystroke? |
I have been testing the commands reported in #661 on Windows and they all worked without this workaround so maybe this issue is platform dependent. I'll check on Linux later to see if I can understand why this is happening. |
As my understanding root issue is atom/atom-keymap#126. |
I think it’s pretty thorough. I know the Swedish layout best, but as far as I know, no layout has I also searched through the keymap file several times to make sure that I didn’t miss anything. And even if I missed something I can add it when somebody reports a problem :) |
will merge and release this, but this is not ideal fix. |
@t9md I will take a look to see if I can fix this issue in atom-keymap. A workaround is good but I agree that it should be fixed in atom-keymap. |
released as v1.28.1 |
Wow, that was fast! Thanks! I wish you the best of luck in fixing this in atom-keymap. |
@lydell Can you help me to understand issue correctly? I want you to do following two things. I want to get keymap info where you hit this issue. so
function clipKeymap() {
const disposable = atom.keymaps.addKeystrokeResolver(event => {
disposable.dispose()
const keymap = JSON.stringify(event.keymap, null, ' ')
atom.clipboard.write(keymap)
})
}
atom.commands.add('atom-workspace', {
'user:clip-keymap': () => clipKeymap(),
}) Let me know if following workaround works for you
atom.keymaps.addKeystrokeResolver(({event}) => {
const {keyCode, key, type} = event
// console.log(keyCode, key, type); // just for debug
// On Linux AltGraph is sent as keyCode 225.
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
//
// When we encounter 225, we want to just ignore to avoid terminate pending state.
// To do that we treat it as bare `ctrl`. Why? `ctrl` is ignored keystroke by folllwing
// isBareModifier(keystroke) chek at here
// https://github.com/atom/atom-keymap/blob/802745d4a2a7740d95c5e3f08e141d15fd349457/src/keymap-manager.coffee#L516
if (keyCode === 225) {
// I just want to know this result for AltGraph(keyCode 225) typed in linux.
console.log(event.getModifierState('AltGraph'));
return 'ctrl'
}
}) |
JSON keymap table
The workaround works! 🎉 |
@lydell Thanks! |
After I found the workaround works from @lydell 's feedback. What I can come up with to fix atom/atom-keymap#126 is to let atom-keymap just ignore keyCode This ignore is done at very top of keyevent handling, atom-keymap would become never handle keyCode
@lydell, @Ben3eeE |
Sorry, I forgot about the You are correct in your understanding about AltGr. It is only used as a modifier. But people don't think about it as a modifier: There are no keyboard shortcuts like altgr+a. AltGr is only used to access a "third layer" of the keyboard containing extra symbols, such as To me it sounds like the correct approach is to ignore KeyCode |
Thanks for clarification, it really getting clear.
|
@t9md On Windows AltGr is the same as Ctrl+Alt so then it can be used as a single modifier because AltGr+o is the same as Ctrl+Alt+o. I don't remember 100% how atom-keymap works with Linux in this case. Also @lydell Can you paste the result of the following script(Just paste it into the Developer tools console and press AltGraph in Atom) when you press AltGraph on Linux: document.addEventListener('keydown', e => console.log(e), true) I opened a PR yesterday that registers AltGraph as a modifier atom/atom-keymap#231. This is because AltGr was a non modifier on Windows because of the Electron upgrade. This may be another way to solve this issue. So AltGraph is currently causing this issue on Windows in Atom 1.25 and it seems on Linux in earlier versions of Atom. I would like to find a solution for both Windows and Linux 💭 |
@t9md Yes, you never press AltGr alone. You hold it down and press another key while it is down, just like you use the shift key. @Ben3eeE Thanks, I had forgotten that AltGr is the same as Ctrl+Alt in Windows. That is not the case on Linux, though. Good to keep in mind. keydown event for AltGr
|
Thanks! |
So this is the same issue that Windows is having but the PR atom/atom-keymap#231 will not work on Linux yet I think but that might be fixable.
This is interesting I would think it's the other way around based on reading the code in atom-keymap. Hmm 💭 I wonder if there are more issues with AltGraph on Linux or if I am misunderstanding something. |
So the issue is that in |
I was also surprised by the order of the |
Yes, this part is confusing, strange. |
For me, after I know that my workaround code in #1031 (comment) works. Like sole Which ever by ignoreing keycode 225 or adding it to |
In many keyboard layouts, such as German, French and Swedish, some
characters have to be typed using the AltGr key. If such a key is the
non-first key of a VMP keyboard shortcut sequence, the sequence fails
to trigger. This is because Atom receive an 'altgraph' key press
inbetween. For example, the shortcut
g ~
is seen asg altgraph ~
.'altgraph' seems to be handled just like any other key, so just like
g a ~
does not exist, neither doesg altgraph ~
.This commit duplicates shortcuts containing problematic AltGr keys. For
example, in addition to the
g ~
shortcut I've addedg altgraph ~
.The keys I did this for are:
~ $ | [ ] { }
.Fixes #661.