mirror of
https://github.com/nushell/reedline.git
synced 2024-09-11 15:55:50 +03:00
Allow binding of CTRL+ALT+<c>, CTRL+ALT+SHIFT+<c>, and <c> (#580)
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 also allows the user to bind a keybinding without modifiers. This affects emacs mode and vi insert mode (vi normal mode already allows such keybindings).
This commit is contained in:
parent
97f754425a
commit
7f54706cab
@ -127,11 +127,16 @@ impl EditMode for Emacs {
|
||||
_ => c.to_ascii_lowercase(),
|
||||
};
|
||||
|
||||
self.keybindings
|
||||
.find_binding(modifier, KeyCode::Char(c))
|
||||
.unwrap_or_else(|| {
|
||||
if modifier == KeyModifiers::NONE
|
||||
|| modifier == KeyModifiers::SHIFT
|
||||
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
||||
|| modifier
|
||||
== KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
|
||||
== KeyModifiers::CONTROL
|
||||
| KeyModifiers::ALT
|
||||
| KeyModifiers::SHIFT
|
||||
{
|
||||
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
||||
if modifier == KeyModifiers::SHIFT {
|
||||
@ -141,10 +146,9 @@ impl EditMode for Emacs {
|
||||
},
|
||||
)])
|
||||
} else {
|
||||
self.keybindings
|
||||
.find_binding(modifier, KeyCode::Char(c))
|
||||
.unwrap_or(ReedlineEvent::None)
|
||||
ReedlineEvent::None
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => self
|
||||
.keybindings
|
||||
|
@ -111,11 +111,16 @@ impl EditMode for Vi {
|
||||
_ => c.to_ascii_lowercase(),
|
||||
};
|
||||
|
||||
self.insert_keybindings
|
||||
.find_binding(modifier, KeyCode::Char(c))
|
||||
.unwrap_or_else(|| {
|
||||
if modifier == KeyModifiers::NONE
|
||||
|| modifier == KeyModifiers::SHIFT
|
||||
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
||||
|| modifier
|
||||
== KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
|
||||
== KeyModifiers::CONTROL
|
||||
| KeyModifiers::ALT
|
||||
| KeyModifiers::SHIFT
|
||||
{
|
||||
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
||||
if modifier == KeyModifiers::SHIFT {
|
||||
@ -125,10 +130,9 @@ impl EditMode for Vi {
|
||||
},
|
||||
)])
|
||||
} else {
|
||||
self.insert_keybindings
|
||||
.find_binding(modifier, KeyCode::Char(c))
|
||||
.unwrap_or(ReedlineEvent::None)
|
||||
ReedlineEvent::None
|
||||
}
|
||||
})
|
||||
}
|
||||
(_, KeyModifiers::NONE, KeyCode::Esc) => {
|
||||
self.cache.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user