Improve keybinding parsing for Unicode support#14020
Improve keybinding parsing for Unicode support#14020sholderbach merged 1 commit intonushell:mainfrom
Conversation
Enhance keybinding parsing to support Unicode character codes: - Added support for specifying keycodes using Unicode codes (e.g., char_u003B for `;`). - Improved flexibility for customizing vi mode keybindings, especially for non-English keyboard layouts.
|
Thanks for trying to help out. I haven't studied your code yet, but I like the idea of expanding this to support |
|
I don't quite follow the example in your motivation. You can define a binding to (we may want to check our general parser/grammar if the behavior of {
name: history_menu
modifier: none
keycode: "char_;"
mode: [emacs, vi_insert, vi_normal]
event: { send: menu name: history_menu }
}One general limitation with some of those special characters is that the ANSI default keyboard protocol will not always carry the modifier info with some of those. What gets transmitted from the terminal is generally really the text. While on a QWERTY keyboard it would correctly show without modifier as found on the layout, with the Russian keyboard it probably won't show the |
Oh, I didn't know you could assign keys like And you are right that |
|
IIRC, I think the issue was less about Found it: https://discord.com/channels/601130461678272522/614593951969574961/1292426188765265951 {
name: enter_vi_insert_mode
modifier: none
keycode: char_ш
mode: vi_normal
event: { *Some magic to change to vi_insert ??* }
} |
Oh, that's a different issue. I have some thoughts about adding a separate variant in |
|
I know getting insert mode to work is a different issue but i thought |
Here the problem seems more towards what can be mapped and not the Our vi mode parser itself is not very advanced at the moment so doesn't permit remapping of anything in the state machine for the normal mode key sequences. So if you |
No, just like the key binding |
ok, my mistake. so, this PR is really about |
I have to disagree on one point: the current implementation doesn't distinguish between uppercase and lowercase Latin characters, meaning you can't assign different actions to A and a, though this is possible for non-Latin characters. Therefore, WYSIWYG isn't fully achieved for Latin characters 🙂. |
Yeah that lazy |
sholderbach
left a comment
There was a problem hiding this comment.
I think I made clear that I am not burning for the feature, but the implementation is sound and it can possibly disambiguate characters on international keyboards. I would not recommend that we use any of those char_u... expressions in the default config and it creeps up the number of things a user may get wrong in their config.
But let's give it a try and make sure that we have some documentation on it.
|
@JustForFun88 it would be good to have some documentation on this change in the upcoming release blog if you have time? here's the current PR that people contribute things like this to nushell/nushell.github.io#1566 |
I think that I can prepare PR tomorrow |
Description
This pull request enhances the
add_parsed_keybindingfunction to provide greater flexibility in specifying keycodes for keybindings in Nushell. Previously, the function only supported specifying keycodes directly through character notation (e.g.,char_efor the charactere). This limited users to a small set of keybindings, especially in scenarios where specific non-English characters were needed.With this new version, users can also specify characters using their Unicode codes, such as
char_u003Bfor the semicolon (;), providing a more flexible approach to customization, for example like this:{ name: move_to_line_end_or_take_history_hint modifier: shift keycode: char_u003B # char_; mode: vi_normal event: { until: [ { send: historyhintcomplete } { edit: movetolineend } ] } }Motivation:
This enhancement allows better customization of vi mode in Nushell. For example, in the Russian layout, the
$symbol (used for 'Move to end of line') coincides with the semicolon (;). Previously, it was not possible to assignchar_;as the keycode, as the parser did not recognize it as a valid Unicode character.This enhancement extends support for specifying keycodes using Unicode character codes (e.g.,
char_u003Bfor;), allowing users to more easily configure Nushell according to their preferred keyboard layouts and enhancing the overall flexibility of keybinding customization.The new implementation preserves the performance of the old one and avoids redundant checks (
c.starts_with("char_")andc.chars().skip(5)).User-Facing Changes
Added support for specifying keycodes using Unicode codes, e.g., char_u002C (comma -
,):{ name: <command_name>, # name of the command modifier: none, # key modifier keycode: char_u002C, # Unicode code for the comma (',') mode: vi_normal, # mode in which this binding should work event: { send: <action> # action to be performed } }