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,24 +127,28 @@ impl EditMode for Emacs {
|
|||||||
_ => c.to_ascii_lowercase(),
|
_ => c.to_ascii_lowercase(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if modifier == KeyModifiers::NONE
|
self.keybindings
|
||||||
|| modifier == KeyModifiers::SHIFT
|
.find_binding(modifier, KeyCode::Char(c))
|
||||||
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
.unwrap_or_else(|| {
|
||||||
|| modifier
|
if modifier == KeyModifiers::NONE
|
||||||
== KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
|
|| modifier == KeyModifiers::SHIFT
|
||||||
{
|
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
||||||
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
|| modifier
|
||||||
if modifier == KeyModifiers::SHIFT {
|
== KeyModifiers::CONTROL
|
||||||
c.to_ascii_uppercase()
|
| KeyModifiers::ALT
|
||||||
|
| KeyModifiers::SHIFT
|
||||||
|
{
|
||||||
|
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
||||||
|
if modifier == KeyModifiers::SHIFT {
|
||||||
|
c.to_ascii_uppercase()
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
},
|
||||||
|
)])
|
||||||
} else {
|
} else {
|
||||||
c
|
ReedlineEvent::None
|
||||||
},
|
}
|
||||||
)])
|
})
|
||||||
} else {
|
|
||||||
self.keybindings
|
|
||||||
.find_binding(modifier, KeyCode::Char(c))
|
|
||||||
.unwrap_or(ReedlineEvent::None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => self
|
_ => self
|
||||||
.keybindings
|
.keybindings
|
||||||
|
@ -111,24 +111,28 @@ impl EditMode for Vi {
|
|||||||
_ => c.to_ascii_lowercase(),
|
_ => c.to_ascii_lowercase(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if modifier == KeyModifiers::NONE
|
self.insert_keybindings
|
||||||
|| modifier == KeyModifiers::SHIFT
|
.find_binding(modifier, KeyCode::Char(c))
|
||||||
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
.unwrap_or_else(|| {
|
||||||
|| modifier
|
if modifier == KeyModifiers::NONE
|
||||||
== KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
|
|| modifier == KeyModifiers::SHIFT
|
||||||
{
|
|| modifier == KeyModifiers::CONTROL | KeyModifiers::ALT
|
||||||
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
|| modifier
|
||||||
if modifier == KeyModifiers::SHIFT {
|
== KeyModifiers::CONTROL
|
||||||
c.to_ascii_uppercase()
|
| KeyModifiers::ALT
|
||||||
|
| KeyModifiers::SHIFT
|
||||||
|
{
|
||||||
|
ReedlineEvent::Edit(vec![EditCommand::InsertChar(
|
||||||
|
if modifier == KeyModifiers::SHIFT {
|
||||||
|
c.to_ascii_uppercase()
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
},
|
||||||
|
)])
|
||||||
} else {
|
} else {
|
||||||
c
|
ReedlineEvent::None
|
||||||
},
|
}
|
||||||
)])
|
})
|
||||||
} else {
|
|
||||||
self.insert_keybindings
|
|
||||||
.find_binding(modifier, KeyCode::Char(c))
|
|
||||||
.unwrap_or(ReedlineEvent::None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(_, KeyModifiers::NONE, KeyCode::Esc) => {
|
(_, KeyModifiers::NONE, KeyCode::Esc) => {
|
||||||
self.cache.clear();
|
self.cache.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user