mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +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,
|
keybinding: &ParsedKeybinding,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
) -> Result<(), ShellError> {
|
) -> 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 {
|
return Err(ShellError::RuntimeTypeMismatch {
|
||||||
expected: Type::String,
|
expected: Type::String,
|
||||||
actual: keybinding.modifier.get_type(),
|
actual: keybinding.modifier.get_type(),
|
||||||
@ -785,20 +785,20 @@ fn add_parsed_keybinding(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut modifier = KeyModifiers::NONE;
|
let mut modifier = KeyModifiers::NONE;
|
||||||
if modifier_str != "none" {
|
if !str::eq_ignore_ascii_case(modifier_str, "none") {
|
||||||
for part in modifier_str.split('_') {
|
for part in modifier_str.split('_') {
|
||||||
match part {
|
match part.to_ascii_lowercase().as_str() {
|
||||||
"control" => modifier |= KeyModifiers::CONTROL,
|
"control" => modifier |= KeyModifiers::CONTROL,
|
||||||
"shift" => modifier |= KeyModifiers::SHIFT,
|
"shift" => modifier |= KeyModifiers::SHIFT,
|
||||||
"alt" => modifier |= KeyModifiers::ALT,
|
"alt" => modifier |= KeyModifiers::ALT,
|
||||||
"super" => modifier |= KeyModifiers::SUPER,
|
"super" => modifier |= KeyModifiers::SUPER,
|
||||||
"hyper" => modifier |= KeyModifiers::HYPER,
|
"hyper" => modifier |= KeyModifiers::HYPER,
|
||||||
"meta" => modifier |= KeyModifiers::META,
|
"meta" => modifier |= KeyModifiers::META,
|
||||||
str => {
|
_ => {
|
||||||
return Err(ShellError::InvalidValue {
|
return Err(ShellError::InvalidValue {
|
||||||
valid: "'control', 'shift', 'alt', 'super', 'hyper', 'meta', or 'none'"
|
valid: "'control', 'shift', 'alt', 'super', 'hyper', 'meta', or 'none'"
|
||||||
.into(),
|
.into(),
|
||||||
actual: format!("'{str}'"),
|
actual: format!("'{part}'"),
|
||||||
span: keybinding.modifier.span(),
|
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 {
|
let error = |valid: &str, actual: &str| ShellError::InvalidValue {
|
||||||
valid: valid.into(),
|
valid: valid.into(),
|
||||||
actual: actual.into(),
|
actual: actual.into(),
|
||||||
@ -837,7 +839,7 @@ fn add_parsed_keybinding(
|
|||||||
|
|
||||||
KeyCode::Char(char)
|
KeyCode::Char(char)
|
||||||
} else {
|
} else {
|
||||||
match keycode {
|
match keycode_lower.as_str() {
|
||||||
"backspace" => KeyCode::Backspace,
|
"backspace" => KeyCode::Backspace,
|
||||||
"enter" => KeyCode::Enter,
|
"enter" => KeyCode::Enter,
|
||||||
"space" => KeyCode::Char(' '),
|
"space" => KeyCode::Char(' '),
|
||||||
@ -860,15 +862,15 @@ fn add_parsed_keybinding(
|
|||||||
.map(KeyCode::F)
|
.map(KeyCode::F)
|
||||||
.ok_or(ShellError::InvalidValue {
|
.ok_or(ShellError::InvalidValue {
|
||||||
valid: "'f1', 'f2', ..., or 'f20'".into(),
|
valid: "'f1', 'f2', ..., or 'f20'".into(),
|
||||||
actual: format!("'{c}'"),
|
actual: format!("'{keycode}'"),
|
||||||
span: keybinding.keycode.span(),
|
span: keybinding.keycode.span(),
|
||||||
})?,
|
})?,
|
||||||
"null" => KeyCode::Null,
|
"null" => KeyCode::Null,
|
||||||
"esc" | "escape" => KeyCode::Esc,
|
"esc" | "escape" => KeyCode::Esc,
|
||||||
str => {
|
_ => {
|
||||||
return Err(ShellError::InvalidValue {
|
return Err(ShellError::InvalidValue {
|
||||||
valid: "a crossterm KeyCode".into(),
|
valid: "a crossterm KeyCode".into(),
|
||||||
actual: format!("'{str}'"),
|
actual: format!("'{keycode}'"),
|
||||||
span: keybinding.keycode.span(),
|
span: keybinding.keycode.span(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user