rust-lang / rust-playground

The Rust Playground
https://play.rust-lang.org/
Apache License 2.0
1.24k stars 207 forks source link

Rust Playground doesn't deal with re-mapped keys correctly. #324

Open vext01 opened 6 years ago

vext01 commented 6 years ago

Hi,

To cut a long story short, I use a Maltron keyboard to keep RSI at bay. It's a totally bonkers looking thing, but it works.

I didn't like the position of the escape key, and swapped it with the windows key, remapping the key in Xorg with (in my .xsession):

xmodmap -e 'keysym Super_L = Escape'

This works for pretty much everything, but not for the rust playground. I'd like to use the playground in vim mode, but have to reach to the original position of the escape key to exit insert mode. The key remapping is to respected for some reason.

Could the Rust playground take xmodmap re-mappings into account?

nightwing commented 6 years ago

Hi the key mapping is normally handled by the browser, and web page by itself can't detect re-mappings. On which browser did you test this? Could you please check which key code is reported by it, using https://w3c.github.io/uievents/tools/key-event-viewer.html?

shepmaster commented 6 years ago

Could the Rust playground take xmodmap re-mappings into account?

I'm equally as surprised as @nightwing, as this should be handled by the OS / browser. On macOS, for example, I've remapped my Caps Lock key to Control and that works fine.

oberien commented 6 years ago

My two cents: I use the neo-layout, which remaps everything and adds the weirdest sort of different mappings (e.g. CapsLock+Shift+w to ω) and it works just fine.

Regarding browsers: I use vivaldi mainly, but it has problems as it still handles keyevents even though the underlying javascript already consumed them. For exmaple in Vim-mode if I press Ctrl+R, first the vim-binding is executed (redo), then by window refreshes due to vivaldi still handling it as reload. In Firefox this doesn't occur and everything works as expected.

vext01 commented 6 years ago

I'm not at the computer with the Maltron keyboard today, so I can't run the key test just yet, but the system in question is running OpenBSD-current/amd64 and a recent version of Firefox.

When I'm next in front of that system I'll update this issue.

Thanks

vext01 commented 6 years ago

Firefox

firefox

Chromium

chromium


So there is some difference.

Escape works fine in the Rust playground on chromium on this system, but not in firefox. In firefox I must press the key's pre-remapped location on the keyboard.

vext01 commented 6 years ago

DId any of that info help? Cheers

EdmundsEcho commented 5 years ago

I was having a similar issue trying to escape from insert mode using either <esc>, <Ctr-[> or <Ctr-l>. I was only able to get it to work using <C-c>.

I used the keyboard input tool mentioned above. It's a great tool. The result for me however, is that Firefox (nor chrome) would record my use of the <esc> key.

Is this something worth noting in the documentation? It took me a while to figure out how to use my vim preference in the Rust Playground... without being able to escape the insert mode, the feature is rendered much less useful.

shepmaster commented 5 years ago

Can you provide reproduction steps? Once I set the playground into Vim mode:

image

I was able to enter edit mode and exit it:

insert

EdmundsEcho commented 5 years ago

Thank you for looking into this. Here is a video of what is happening at my end... I'm not as proficient as you seem to be with video production... this said, you should see that I'm in Vim mode. I try to use while in insert mode to no avail. However, works.

https://im.ezgif.com/tmp/ezgif-1-f1f4182f809d.gif

vext01 commented 5 years ago

I don't know what changed, but my re-mapped escape key now works in vim mode on the rust playground under firefox.

aldanor commented 5 years ago

It would be invaluable if it was possible to remap esc in vim mode to a sequence of characters... almost all vim users out there use either fd, jk, jj, kj or one of those...

Would that be feasible?

nightwing commented 5 years ago

It is already possible to remap vim keys by typing : imap jj <Esc>. To remap from javascript require("ace/keyboard/vim").Vim.map("xx", "<Esc>", "insert") can be used.

shepmaster commented 5 years ago

@aldanor I'm not a vi/vim user so I only understand the very basics of what you are asking :-) Does what @nightwing suggested work for your case?

EdmundsEcho commented 3 years ago

@shepmaster Yes, the solution @nightwing suggests would be really helpful. The key to the spec is the ability to map 2 char to the escape functionality (per the "xx" described). I truly think this is one of those "minimum input, maximum output" fixes... at least I can attest to the value of the output :))