diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index 80ae28b103..1b09e59166 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -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(), }); }