zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.39k stars 1.16k forks source link

Inconsistent keybindings behavior for Alt Shift Combinations #3305

Open Neko-Box-Coder opened 1 month ago

Neko-Box-Coder commented 1 month ago

Description of the problem or steps to reproduce

When using the same keybindings on Windows and Linux, one works and the other does not.

Given there are two keybindings that are the same but displayed differently

The first one works on Windows but not on Linux, vice versa for the second one.

I tried both by pointing it to empty config directory using micro -config-dir ./tmp and modifying the keybindings there

When running raw, I can see indeed it is capturing different things

On Linux

EventKey: Alt-E: "\x1bE"

On Windows

EventKey: Shift-Alt-E: ""

Specifications

Commit hash: 1f51d0b9 (Windows) 91765082 (Linux) OS: Windows 11 and Arch Linux Terminal: WezTerm

dmaluka commented 1 month ago

Yeah, on Unix it is Alt-E, with capital E (note that it is different from Alt-e), since Shift-e is the capital E letter.

This is one of many unfortunate consequences of all the legacy crap that Unix terminals have and the lack of standardization between them, as well as the lack of standardization between Unix and Windows terminals.

Neko-Box-Coder commented 1 month ago

Yeah, right now I have 2 versions of keybindings (1 with Shift 1 without) that binds to the same action as a workaround so that I can use the same json for both Linux and Windows.

I will create a PR to fix this.

Neko-Box-Coder commented 1 month ago

@JoeKar This is actually kinda similar to #3304 and the fix I am working on at the moment is to try both "Alt-E" and "Alt-Shift-E" if it is a capital letter and stop trying if we matched.

This is less important than #3304 (but slightly inconvenient) so I am not too fussed about getting this sorted quickly. But my question would be should tcell be producing consistent output for this as well, considering tcell is just spitting out whatever it receives and this count as the quirks with linux vs windows.

JoeKar commented 1 month ago

I assume that this is related to tcell's input mode and how it receives the the key codes. Currently the terminal generates a Shift+e instead of a E, which results in Shift-Alt-E, while under Linux it receives the E directly (without the Shift) and this is then Alt-E. Maybe the situation would be different, when tcell activates modeVtInput, but this is just an untested guess.