atom/atom-keymap

Cannot use numeric keypad to type special characters

Closed this issue · 9 comments

Several special characters are not available on a standard keyboard, but are still important in many languages, for example any of these: êëéô. The way to type these is by holding Alt while typing the ASCII code, so ê becomes Alt+136 and so on. This works universally in all Windows applications I have ever encountered, including all the tabbed text editors. In all of those editors (and in Chrome, Firefox and whatever Microsoft's browser is called) you can switch between tabs by holding down Ctrl and pressing the tab number (so Ctrl+3 for the third tab).

For reasons I am not privy to, Atom uses Alt along with the tab number, which means that typing Alt+136 will switch away from the tab I'm typing in, to first tab 1, then tab 3 and finally tab 6, where the character will finally be inserted (possibly replacing something unrelated to what I'm working on).

According to the key binding resolver, these are the bindings involved:
Alt+3 binds to pane:show-item-3
Ctrl+3 binds to tree-view:open-selected-entry-in-pane-3

Fabulous. I would imagine the only sensible solution is to change it as follows:
Ctrl+3 binds to pane:show-item-3 (in keeping with all other applications I have ever encountered)
Ctrl+Shift+3 binds to tree-view:open-selected-entry-in-pane-3 (it seems useful, but the mapping is not intuitive).

The obvious workaround seems to be to modify the key bindings. So I did this:

'body':
  'alt-1': 'native!'
  'alt-2': 'native!'
  'alt-3': 'native!'
  'alt-4': 'native!'
  'alt-5': 'native!'
  'alt-6': 'native!'
  'alt-7': 'native!'
  'alt-8': 'native!'
  'alt-9': 'native!'
  'ctrl-1': 'pane:show-item-1'
  'ctrl-2': 'pane:show-item-2'
  'ctrl-3': 'pane:show-item-3'
  'ctrl-4': 'pane:show-item-4'
  'ctrl-5': 'pane:show-item-5'
  'ctrl-6': 'pane:show-item-6'
  'ctrl-7': 'pane:show-item-7'
  'ctrl-8': 'pane:show-item-8'
  'ctrl-9': 'pane:show-item-9'

And it doesn't even work a little bit. I also tried using unset! instead of native!, but it also makes no difference. The Alt+number keystrokes keep mucking around with my tabs. And this makes it incredibly frustrating when I need to type in anything other than English.

Atom version is 1.11.0-beta5 running on Windows 7

And this makes it incredibly frustrating when I need to type in anything other than English.

While this is not a solution to your problem, I would suggest using different keyboard layouts rather than using the numpad. non-US keyboard layouts will have proper support in Atom starting with Atom 1.12.0.

I would suggest using different keyboard layouts rather than using the numpad...

Well, that depends on where you live. Many areas in the world only use US layout keyboards and using a layout in Windows that emulates those characters causes problems when programming.

For example, ë may be emulated by pressing the character sequence "e but that causes great annoyance when programming and you want to start a string with the letter e. I would go as far as saying that those layouts are much more trouble than they're worth unless you spend your life in Excel and Word.

Also, I'm bilingual and do a lot of work in English as well, so it's far easier to be explicit when I need one of these characters than depend on a Windows keyboard layout to guess what I need.

But the overriding point is actually still that Atom effectively disables this way of typing which is supported anywhere and everywhere. You can literally go try it in any other application and the odds are you won't find even one that does what Atom does. Even VS Code (which is a fork of Atom) works as expected.

Finally, the use of Ctrl+number to switch to tabs is such a widespread standard that it does not make sense for Atom to use a different shortcut.

I can't reproduce this. @CobusK has this been fixed for you in the latest version of Atom where international keyboard support has been improved?

I copied your keybindings to my keymap.cson and pressed Alt+136 on the numpad and it wrote ê in the TextEditor. Without the keymap changes this wouldn't work for the mentioned reasons.

@damieng Do you have any 💭 on changing these keybindings as part of the AltGr remapping effort for improved support?

Edit: Or maybe we can resolve numpad to something different since those keys are not the same.

image

@Ben3eeE I managed to work around it now with the keymap shown below, but without that remapping, it acts exactly like I described. My Atom version is 1.13.0-beta4.

Here's the keymap:
'.platform-win32 .tree-view, .platform-linux .tree-view':
'ctrl-1': 'native!'
'ctrl-2': 'native!'
'ctrl-3': 'native!'
'ctrl-4': 'native!'
'ctrl-5': 'native!'
'ctrl-6': 'native!'
'ctrl-7': 'native!'
'ctrl-8': 'native!'
'ctrl-9': 'native!'
'ctrl-shift-1': 'tree-view:open-selected-entry-in-pane-1'
'ctrl-shift-2': 'tree-view:open-selected-entry-in-pane-2'
'ctrl-shift-3': 'tree-view:open-selected-entry-in-pane-3'
'ctrl-shift-4': 'tree-view:open-selected-entry-in-pane-4'
'ctrl-shift-5': 'tree-view:open-selected-entry-in-pane-5'
'ctrl-shift-6': 'tree-view:open-selected-entry-in-pane-6'
'ctrl-shift-7': 'tree-view:open-selected-entry-in-pane-7'
'ctrl-shift-8': 'tree-view:open-selected-entry-in-pane-8'
'ctrl-shift-9': 'tree-view:open-selected-entry-in-pane-9'

'body':
'alt-1': 'native!'
'alt-2': 'native!'
'alt-3': 'native!'
'alt-4': 'native!'
'alt-5': 'native!'
'alt-6': 'native!'
'alt-7': 'native!'
'alt-8': 'native!'
'alt-9': 'native!'
'ctrl-1': 'pane:show-item-1'
'ctrl-2': 'pane:show-item-2'
'ctrl-3': 'pane:show-item-3'
'ctrl-4': 'pane:show-item-4'
'ctrl-5': 'pane:show-item-5'
'ctrl-6': 'pane:show-item-6'
'ctrl-7': 'pane:show-item-7'
'ctrl-8': 'pane:show-item-8'
'ctrl-9': 'pane:show-item-9'

So to confirm, the alt-number keybindings are interfering with the numeric keypad and without rebinding using alt-numpad to write characters is not possible. This is what I observed when testing this. In your original post you said that rebinding did not work.

The solution here is then to either resolve numpad differently or to rebind and not use alt-number keybindings in core so users don't need to unset these keybindings to use alt-numpad.

I'm definitely thinking numeric keypad should be treated differently - at least for Windows with alt keys. (and linux if it also uses this mechanism for unicode entry)

@Ben3eeE Yes, in my original post you'll see I just rebinded (rebound?) for body. In the newer post (which is working), I also did the same on other classes too. Also, unset! didn't work, only native!

I wish to reiterate that switching tabs by number seems to use the Ctrl key-mapping absolutely everywhere else I've seen. So for Atom to use Alt doesn't really make sense, even if tab switching and the keypad can both live on the Alt key.

Yeah I agree that Alt-number can be unintuitive given how wide spread Ctrl-number seems to be, and we have had issues for it, for example atom/tabs#391. But we don't like changing the defaults unless we absolutely have to. We have had Alt-number for a long time and many might have become used to it.

Resolving numpad differently seems like a the best option, we get to keep the current default and can still use Alt-numpad to write these characters. Does anyone know how other programs work with the numpad? Does it resolve it differently?

@Ben3eeE I can't speak for Linux (or Chromium for that matter), but on Windows there are separate key constants to identify the keypad characters. So maybe that can work. If not an alternate strategy could be to simply delay the tab switching until after Alt is released and then cancel it if more than one number was pressed. I think this may be more difficult to implement though, as it will need to not affect other instances of a shift key + more than one character (like holding Ctrl while pressing Tab repeatedly).