mirror of
https://github.com/nushell/nushell.git
synced 2024-11-21 16:03:19 +01:00
Fix deleted lowercase in keybinding parsing (#14081)
# Description Adds back the `to_ascii_lowercase` deleted in #13802. Also fixes the error messages having the lowercased value instead of the original value.
This commit is contained in:
parent
a11c9e9d70
commit
a0f38f8845
@ -776,7 +776,7 @@ fn add_parsed_keybinding(
|
||||
keybinding: &ParsedKeybinding,
|
||||
config: &Config,
|
||||
) -> Result<(), ShellError> {
|
||||
let Ok(modifier_str) = keybinding.modifier.as_str().map(str::to_ascii_lowercase) else {
|
||||
let Ok(modifier_str) = keybinding.modifier.as_str() else {
|
||||
return Err(ShellError::RuntimeTypeMismatch {
|
||||
expected: Type::String,
|
||||
actual: keybinding.modifier.get_type(),
|
||||
@ -785,20 +785,20 @@ fn add_parsed_keybinding(
|
||||
};
|
||||
|
||||
let mut modifier = KeyModifiers::NONE;
|
||||
if modifier_str != "none" {
|
||||
if !str::eq_ignore_ascii_case(modifier_str, "none") {
|
||||
for part in modifier_str.split('_') {
|
||||
match part {
|
||||
match part.to_ascii_lowercase().as_str() {
|
||||
"control" => modifier |= KeyModifiers::CONTROL,
|
||||
"shift" => modifier |= KeyModifiers::SHIFT,
|
||||
"alt" => modifier |= KeyModifiers::ALT,
|
||||
"super" => modifier |= KeyModifiers::SUPER,
|
||||
"hyper" => modifier |= KeyModifiers::HYPER,
|
||||
"meta" => modifier |= KeyModifiers::META,
|
||||
str => {
|
||||
_ => {
|
||||
return Err(ShellError::InvalidValue {
|
||||
valid: "'control', 'shift', 'alt', 'super', 'hyper', 'meta', or 'none'"
|
||||
.into(),
|
||||
actual: format!("'{str}'"),
|
||||
actual: format!("'{part}'"),
|
||||
span: keybinding.modifier.span(),
|
||||
});
|
||||
}
|
||||
@ -814,7 +814,9 @@ fn add_parsed_keybinding(
|
||||
});
|
||||
};
|
||||
|
||||
let keycode = if let Some(rest) = keycode.strip_prefix("char_") {
|
||||
let keycode_lower = keycode.to_ascii_lowercase();
|
||||
|
||||
let keycode = if let Some(rest) = keycode_lower.strip_prefix("char_") {
|
||||
let error = |valid: &str, actual: &str| ShellError::InvalidValue {
|
||||
valid: valid.into(),
|
||||
actual: actual.into(),
|
||||
@ -837,7 +839,7 @@ fn add_parsed_keybinding(
|
||||
|
||||
KeyCode::Char(char)
|
||||
} else {
|
||||
match keycode {
|
||||
match keycode_lower.as_str() {
|
||||
"backspace" => KeyCode::Backspace,
|
||||
"enter" => KeyCode::Enter,
|
||||
"space" => KeyCode::Char(' '),
|
||||
@ -860,15 +862,15 @@ fn add_parsed_keybinding(
|
||||
.map(KeyCode::F)
|
||||
.ok_or(ShellError::InvalidValue {
|
||||
valid: "'f1', 'f2', ..., or 'f20'".into(),
|
||||
actual: format!("'{c}'"),
|
||||
actual: format!("'{keycode}'"),
|
||||
span: keybinding.keycode.span(),
|
||||
})?,
|
||||
"null" => KeyCode::Null,
|
||||
"esc" | "escape" => KeyCode::Esc,
|
||||
str => {
|
||||
_ => {
|
||||
return Err(ShellError::InvalidValue {
|
||||
valid: "a crossterm KeyCode".into(),
|
||||
actual: format!("'{str}'"),
|
||||
actual: format!("'{keycode}'"),
|
||||
span: keybinding.keycode.span(),
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user