rhysd / NyaoVim

Web-enhanced Extensible Neovim Frontend
Other
2.21k stars 57 forks source link

Does not work with Neo2 keymap #10

Open SirVer opened 8 years ago

SirVer commented 8 years ago

The neo2 keymap is an ergonomic keyboard layout.

It works great for most apps, but this one is not passing through special keys like ~:? which are using special modifier keys. Atom had similar issues: https://github.com/atom/atom/issues/3834 which leads me to believe that it is probably an issue with many keymaps, not only Neo.

rhysd commented 8 years ago

I knew Neo2 keyboard layout at first time... Looks nice!

Could you tell me how you input special keys such as ~, :, ?? From your link, the keyboard layout seems to have some states and such special keys can be input on one of them. I guess they require some modifier key.

NyaoVim currently handles inputs which include modifier key (e.g. <C-l>) via keydown event and other non-modifier inputs (e.g. a, A, and so on) via input event of <input> element. (source code)

Let me explain with : input for example. In normal keyboard, : requires shift + ; input. It is not caught on keydown event because no modifier key (ctrl, alt) is pushed. Then the input : is caught on input event and NyaoVim sends sequence : to Neovim process.

But if your keyboard includes modifier key on inputting :, NyaoVim wrongly catches it on keydown event.

I think it is very helpful to show me the KeyboardEvent instance on keydown event when you input : on Chrome (or Chromium).

SirVer commented 8 years ago

Could you tell me how you input special keys such as ~, :, ??

Sure, for example ? is inputted by holding CAPSLOCK + h or # + h (on an qwertz keyboard). Capslock or # function as an additional modifier keys, similar to LSHIFT and RSHIFT but enabling another layer (not capital letters, but special symbols). There is one more set of modifier keys: < and RIGHT_CMD enable numlock and cursor keys.

I think it is very helpful to show me the KeyboardEvent instance on keydown event when you input : on Chrome (or Chromium).

I am a backend developer, I am not familiar with debugging inside chrome. If you tell me how to get this data, I will provide it.

rhysd commented 8 years ago

Thank you for description.

Sure, for example ? is inputted by holding CAPSLOCK + h or # + h (on an qwertz keyboard). Capslock or # function as an additional modifier keys, similar to LSHIFT and RSHIFT but enabling another layer (not capital letters, but special symbols). There is one more set of modifier keys: < and RIGHT_CMD enable numlock and cursor keys.

Hmm... CAPSLOCK and other keys used as modifier may cause this issue. I want to know what they send to browser.

I am a backend developer, I am not familiar with debugging inside chrome. If you tell me how to get this data, I will provide it.

OK, let me explain.

1. Write below HTML as index.html

<body>
<body>
<script>
  window.addEventListener('keydown', function (e) { console.log(e); });
</script>

2. Start http server

python -m SimpleHTTPServer 1234

3. Open http://localhost:1234 in Chrome and DevTools (Cmd + option + i or from tool bar menu).

4. Send the key from keyboard

5.Please show me the result in console of DevTools as below

2015-12-31 18 18 40

SirVer commented 8 years ago

I inserted ? which is Mod3 + h. I did it once with the left Mod3 which is CAPSLOCK and once with the right mod3 which is #. Note that under Mac OS X Mod3 == ALT.

Left one: it send two events, once for pressing (and holding CAPSLOCK) and one for the h key:

CAPSLOCK:

screen shot 2016-01-03 at 11 05 52

then H:

screen shot 2016-01-03 at 11 06 38

Now the right side, first pressing #:

screen shot 2016-01-03 at 11 07 41

and pressing h:

screen shot 2016-01-03 at 11 08 07
rhysd commented 8 years ago

Sorry for late response and thank you very much for these screenshots. They're very helpful.

It seems that your keyboard sends altKey: true on those keys. <neovim-editor> recognizes it as you sent modifier key. For example, H sends altKey: true and key code 191 (char: "¿") hence <neovim-editor> recognizes it as <A-¿>.

This problem currently can't be solved because we can't know which keyboard is used.

However, there may still be possibility to fix this problem. As new member of KeyboardEvent, code will be added. (MDN document) If code is added, we can use it in stead of key code and no longer need to convert key code. It means that hopefully any input can be caught in spite of keyboard layouts. Unfortunately KeyboardEvent.code is not implemented to Chromium 47 (latest Electron) yet, but Chrome 48 beta already seemed to implement it. After Electron introducing Chromium 48, we can try KeyboardEvent.code. So I'll open this issue for that.

SirVer commented 8 years ago

sounds promising. Thank you.

milibopp commented 8 years ago

maybe this helps you narrow down the issue: I am using Neo2 as well and just tried NyaoVim. I have not experienced any of the aforementioned problems using NyaoVim's AUR package for Arch Linux.

rhysd commented 8 years ago

Thank you for the comment! I already added the implementation which handles key input with KeyboardEvent.key. I forgot notifying it in this issue..

milibopp commented 8 years ago

Ah, cool. Thank you for improving my first impression of NyaoVim then!

rhysd commented 8 years ago

No any other problem about Neo2 was reported for 1 week. I think latest version already solved this issue. (I can't confirm it because of not having the keyboard.)

I'll close this window. If anyone notice a problem about this issue, please ping me in this issue. And then I'll reopen this issue.

SirVer commented 8 years ago

Sorry, late to the party.

I just retried that and Neo2 is not working for me properly. The Shift and Mod4 modifiers are working, but Mod3 modifiers are not generating the correct symbols. For example, the above mentioned Mod3 + h now inserts Mod3 + h a ¿ instead of ?.

nyaovim --version                                            
NyaoVim version 0.0.12
  electron : 0.36.5
  chrome : 47.0.2526.110
  node : 5.1.1
  v8 : 4.7.80.27
rhysd commented 8 years ago

@SirVer

Thank you for checking. I'll investigate.

rhysd commented 8 years ago

@SirVer

I want to confirm more. Could you tell me your environment (OS X? Linux? if Linux, which distribution? etc)?

SirVer commented 8 years ago

@rhysd this is on OS X, still same setup (see above, I posted the debug out some time back).

rhysd commented 8 years ago

Ah, sorry for duplicate question. I missed the description. And thank you for the answer, I got it.

rhysd commented 8 years ago

I added new property disable-alt-key to <neovim-editor> component in ~/.config/nyaovim/nyaovimrc.html. If this property is on, NyaoVim ignores alt key input so that keyboard which uses alt key as special modifier is available. Please note that <A-x> mapping will be unavailable.

e.g.

<neovim-editor
  id="nyaovim-editor"
  argv$="[[argv]]"
  font="Monaco,monospace"
  font-size="14"
  line-height="1.5"
  disable-alt-key
></neovim-editor>

To use this, please reinstall nyaovim package and ensure version ofneovim-component package is 0.4.4. (NyaoVim depends on it)

I added this workaround because NyaoVim can't know which alt key or modifier key is pressed from altKey in KeyboardEvent.