coolwanglu / neovim-e

Electron UI for Neovim
MIT License
271 stars 29 forks source link

Azerty not working #32

Open Armaklan opened 9 years ago

Armaklan commented 9 years ago

Azerty keyboard dont work.

Letter press is correctly print in screen, but all symbol (number, ponctuation, ...) is not from azerty keyboard.

coolwanglu commented 9 years ago

That's probably because the scancode is used. I wonder if you have tried Atom (the editor), is your keyboard working well there?

Armaklan commented 9 years ago

Keyboard work in Atom Editor.

coolwanglu commented 9 years ago

OK, let me see if I can find the issue, as the code that processes keyboard events were taking from Atom. But it could be difficult as I don't have an Azerty keyboard.

Armaklan commented 9 years ago

Ok. Feel free to ask me to test some modification.

Armaklan commented 9 years ago

I try to replace keydown event by keypress event. Many character work well (like : ) by i think we must rebind code of function button => actually "z" is bind on F11

q12321q commented 9 years ago

Indeed the keypress event is the only way to go. AFAIK it's not possible to properly handle localized or punctuation characters via the keydown event. Unfortunately, some special keys like or do not fire the keypress event. So we need to keep both.

I propose to keep keydown for the special keys and then handle others with the keypress event. I'll fork and try to implement something as a POC. It'll need a lot of tests to handle every cases.

@coolwanglu: you don't need a physical AZERTY keyboard to test. It's depend on which system you are but you can easily change the layout.

coolwanglu commented 9 years ago

@q12321q Is there a library for this?

q12321q commented 9 years ago

for what?

coolwanglu commented 9 years ago

Translate keycode to localized characters.

q12321q commented 9 years ago

Unfortunately, no. There're many attempts but all of them seems clumsy/kludgy and not exhaustive. If you look on the web about keypress vs keydown, you'll find a lot of guys trying to solve this issue. The only reasonable solution is for me to use the keypress event.

q12321q commented 9 years ago

And here we are lucky because keycode are also local to every browser. For a same character, you can have different keycode in chrome and firefox...

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

q12321q commented 9 years ago

I updated the fork (https://github.com/q12321q/neovim-e) with the implementation of my previous comment:

@coolwanglu what do you think?

q12321q commented 9 years ago

Some readings: https://github.com/atom/atom-keymap/issues/37 https://github.com/andischerer/atom-keyboard-localization

It won't be that easy to solve...

coolwanglu commented 9 years ago

@q12321q Indeed I switched 'keypress' to 'keydown' before, just to handle special characters. To use both events, we need to make sure that each physical key press is handled only once by either handler, and we might need to test on different platforms.

atom-keyboard-localiztion looks neat, do you think we can use its code?

q12321q commented 9 years ago

I start to think that the keypress solution is maybe a dead end... I'm not sure we will be able to handle the Ctrl chords like that. Keypress give us the charCode of the result of Ctrl-a but not the charCode of "a" + the fact that with use Ctrl. So I can't build the string "< C-a >" to send to nvim but instead I directly send the character itself. I'm fortunate that it works with a but it doesn't for all non ASCII and punctuation characters. I'll look a bit more into atom-keyboard-localization

coolwanglu commented 9 years ago

Indeed. That's quite a mess. Hopefully with the localization module, a mapping can be chosen based on the keyboard layout specified by users, and the key events will be simply mapped accordingly. Good luck!

q12321q commented 9 years ago

OK, I did some search again and I found no perfect solution. Atom has the same issues and like us have no clean solution. atom-keyboard-localization fix a lot of things but has the major drawback to maintain a non exhaustive tables of key mappings and the need to manually define on which keyboard you are.

But we have a hope: DOM3 with the implementation of the key value in the keydown event: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key It'll solve all our problems and will drastically lighten the code. The problem is it's not yet implemented in chrome: https://www.chromestatus.com/feature/4748790720364544 They're working on it and we may hope to have it soon. Firefox has already done the job and you can try it on the lastest version with this page: https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html

In the mean time if you want, we can implement something like atom do:

You'll always have the correct character when typing a text and we could only have limitations on key combinations.

Thoughs?

coolwanglu commented 9 years ago

I don't know how long we should wait for KeyboardEvent. I remember our keydown and keypress events can also be simplified with it.

So it depends on whether you want this feature in the near future.

q12321q commented 9 years ago

Of course it could take at least several months or years to wait for the KeyboardEvent.key feature. Dev is always longer than we think but it's good to know that we'll have a real solution. It's pretty important for a text editor to be reliable while typing characters :)

Today, neovim-e is unusable on non-US keyboard: the ':' is not available. It also depends how much you want to invest into neovim-e: is it a POC or a real software with a futur?

coolwanglu commented 9 years ago

@q12321q It started as a simply POC, or a toy :). But I'm happy to find that people started to report bugs and send PRs. While I will have limited time on this project, I'd love to make fixes and merge PRs.