Coder Social home page Coder Social logo

Azerty not working about neovim-e HOT 20 OPEN

coolwanglu avatar coolwanglu commented on September 27, 2024
Azerty not working

from neovim-e.

Comments (20)

coolwanglu avatar coolwanglu commented on September 27, 2024

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

from neovim-e.

Armaklan avatar Armaklan commented on September 27, 2024

Keyboard work in Atom Editor.

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

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.

from neovim-e.

Armaklan avatar Armaklan commented on September 27, 2024

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

from neovim-e.

Armaklan avatar Armaklan commented on September 27, 2024

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

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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.

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

@q12321q Is there a library for this?

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

for what?

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

Translate keycode to localized characters.

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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.

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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

  • add keypress event to handle "printable characters"
  • keep keydown event for specials characters only
    From my first tests, It works pretty well except for Ctrl-NonASCIICharacters: it's major issue since Ctrl-] is a common shortcut. We'll have to think of something.

@coolwanglu what do you think?

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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

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

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

@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?

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

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!

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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:

  • keypress handle all singles characters without Ctrl or Alt
    • So all international and punctuation characters are handle
    • Dead keys are handle ( ^ + e -> ĂȘ)
    • Alt+Number works ( Alt+0199 -> Ç)
  • keydown handle special keys and key combination
    • Use localized keycode tables like atom-keyboard-localization to handle Ctrl+, Alt+ and Meta+
    • had a option somewhere to select localized layout

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

Thoughs?

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

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.

from neovim-e.

q12321q avatar q12321q commented on September 27, 2024

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?

from neovim-e.

coolwanglu avatar coolwanglu commented on September 27, 2024

@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.

from neovim-e.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.