rhysd / neovim-component

<neovim-editor> WebComponent to embed Neovim to your app with great ease
https://github.com/rhysd/NyaoVim
MIT License
193 stars 18 forks source link

Keyboard code #15

Closed romgrk closed 8 years ago

romgrk commented 8 years ago

I never ever coded in typescript, but I've run the build here, and all works fine. Dont hesitate to discard and use your own implementation.

romgrk commented 8 years ago

Actually let me run some tests. Getting weird results when using non-US layout.

romgrk commented 8 years ago

So, this setup seems to work for all cases on my side, but let me know what you think, the documentation is vague on some aspects. (Not to mention the This article is in need of a technical review. at the top of the MDN doc)

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

rhysd commented 8 years ago

I also tried KeyboardEvent.key now with Electron 0.36.3 but it didn't work.

Below is a keydown event for Alt+a in OS X:

2016-01-13 22 40 47

The key is wrongly å. This is because OS X handles Alt+a in OS level. I think #14 is still there.

And second case is Ctrl+a:

2016-01-13 22 47 06

The key is empty. I don't check the spec of KeyboardEvent.key tightly, but I guess that Ctrl+a makes no character input so the key is empty.

But this is no problem, we can parse KeyboardEvent.code to get correct key user entered. I'll totally rewrite keydown event handling.

romgrk commented 8 years ago

Ya, I'll let you go ahead with KeyboardEvent.code, the specs for .key seems to vary a lot from one OS to another. Let me know if you need help for testing. (I have various linux/windows versions).

romgrk commented 8 years ago

Oh, and btw this is good to know: From some tests I have run here, the key property might appear as empty in the console (shown as ""), but it is actually equal to something else. In my case it was equal to '\u000E', therefore it was showing as "", but event.key == "" was false. (This is actually in the specs I think)

rhysd commented 8 years ago

From some tests I have run here, the key property might appear as empty in the console (shown as ""),

Oh, I seemed to misunderstand it. I'll consider again and implement key handling. Thanks!

rhysd commented 8 years ago

Anyway, Alt+{char} inputs in OS X is an edge case. I might handle them exceptinally :pensive: