Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow binding of CTRL+ALT+<c>, SHIFT+<c> and CTRL+ALT+SHIFT+<c> #580

Merged
merged 1 commit into from
May 5, 2023

Conversation

TrMen
Copy link
Contributor

@TrMen TrMen commented May 5, 2023

Context

Nushell exposes control_alt and similar keybinding modifiers, but currently it's not possible to actually use those mappings in nushell (at least on none of my keyboards).

From some limited testing, it appears like GNU readline also doesn't allow mapping CTRL+ALT+f and similar keybinds. I don't know if there's some deeper reason behind this, or just a limitation of readline itself. I can't think of any edgecases my change would break, since it's only if you actively choose to add a binding.

I use those keybinds quite extensively in other shells, so it'd be nice to have in nu as well.

Commit message

Combinations like Ctrl+Alt+q could not be mapped previously, since some non-us keyboard layouts use those combinations for sending characters like @.

Now, first check if there a binding was defined using that combination, else interpret as raw characters. This should not affect those special keyboard layouts, since they would be sending Ctrl+Alt+<special char>, rather than what would be on the US layout.

E.g.

  • Map Ctrl+Alt+q to an action
  • Ctrl+Alt+q on (some) german keyboards would send @
  • A german layout pressing those keys would send a key combination of Ctrl+Alt+@, so they are unaffected by this change (they would have to specifically map Ctrl+Alt+@)
  • For any layout actually sending Ctrl+Alt+q, they get the mapped action

This affects emacs mode and vi insert mode (vi normal mode already allows such keybindings).

Combinations like `Ctrl+Alt+a` could not be mapped previously, since
some non-us keyboard layouts use those combinations for sending
characters like `@`.

Now, first check if there a binding was defined using that combination,
else interpret as raw characters. This should not affect those special
keyboard layouts, since they would be sending `Ctrl+Alt+<special char>`,
rather than what would be on the US layout.

E.g.
- Map `Ctrl+Alt+a` to an action
- `Ctrl+Alt+a` on (some) german keyboards would send `@`
- A german layout pressing those keys would send a key combination of `Ctrl+Alt+@`,
  so they are unaffected by this change (they would have to specifically
  map `Ctrl+Alt+@`)
- For any layout actually sending `Ctrl+Alt+a`, they get the mapped action

This affects emacs mode and vi insert mode (vi normal mode
already allows such keybindings).
Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

Yes with your change we should be able to relax the rules around both the AltGr maps as well as if someone tries to do some more insidious binding of keys without modifiers. (e.g. clear the buffer if you enter a ! :P )

Closes #546 in that latter aspect.
Closes nushell/nushell#8977

@sholderbach sholderbach linked an issue May 5, 2023 that may be closed by this pull request
@sholderbach sholderbach merged commit 7f54706 into nushell:main May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mapping keys without modifiers
2 participants