refactor(keymap): add Char key fallback and remove unused SHIFT binding
Improve keymap lookup for Char keys by adding fallback to NONE modifiers. Terminals vary in whether they send SHIFT for uppercase/symbol characters, so we now retry without modifiers when an exact match fails. Also removed the unused shift variable and updated key bindings to use NONE modifiers instead of SHIFT for consistency. Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M)
This commit is contained in:
@ -133,9 +133,21 @@ impl Keymap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Look up the binding for a key.
|
/// Look up the binding for a key.
|
||||||
|
/// For Char keys, if exact (key, mods) match fails, retries with NONE
|
||||||
|
/// modifiers since terminals vary in whether they send SHIFT for
|
||||||
|
/// uppercase/symbol characters.
|
||||||
pub fn lookup(&self, key: KeyCode, mods: KeyModifiers) -> Option<&Binding> {
|
pub fn lookup(&self, key: KeyCode, mods: KeyModifiers) -> Option<&Binding> {
|
||||||
self.bindings
|
self.bindings
|
||||||
.get(&KeyPattern::Key(key, mods))
|
.get(&KeyPattern::Key(key, mods))
|
||||||
|
.or_else(|| {
|
||||||
|
// Retry Char keys without modifiers (shift is implicit in the char)
|
||||||
|
if matches!(key, KeyCode::Char(_)) && mods != KeyModifiers::NONE {
|
||||||
|
self.bindings
|
||||||
|
.get(&KeyPattern::Key(key, KeyModifiers::NONE))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
if matches!(key, KeyCode::Char(_)) {
|
if matches!(key, KeyCode::Char(_)) {
|
||||||
self.bindings.get(&KeyPattern::AnyChar)
|
self.bindings.get(&KeyPattern::AnyChar)
|
||||||
@ -222,7 +234,6 @@ impl KeymapSet {
|
|||||||
let mut set = Self::new(registry);
|
let mut set = Self::new(registry);
|
||||||
let none = KeyModifiers::NONE;
|
let none = KeyModifiers::NONE;
|
||||||
let ctrl = KeyModifiers::CONTROL;
|
let ctrl = KeyModifiers::CONTROL;
|
||||||
let shift = KeyModifiers::SHIFT;
|
|
||||||
|
|
||||||
// ── Normal mode ──────────────────────────────────────────────────
|
// ── Normal mode ──────────────────────────────────────────────────
|
||||||
let mut normal = Keymap::new();
|
let mut normal = Keymap::new();
|
||||||
@ -251,9 +262,9 @@ impl KeymapSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Jump to boundaries
|
// Jump to boundaries
|
||||||
normal.bind(KeyCode::Char('G'), shift, "jump-last-row");
|
normal.bind(KeyCode::Char('G'), none, "jump-last-row");
|
||||||
normal.bind(KeyCode::Char('0'), none, "jump-first-col");
|
normal.bind(KeyCode::Char('0'), none, "jump-first-col");
|
||||||
normal.bind(KeyCode::Char('$'), shift, "jump-last-col");
|
normal.bind(KeyCode::Char('$'), none, "jump-last-col");
|
||||||
|
|
||||||
// Scroll
|
// Scroll
|
||||||
normal.bind_args(KeyCode::Char('d'), ctrl, "scroll-rows", vec!["5".into()]);
|
normal.bind_args(KeyCode::Char('d'), ctrl, "scroll-rows", vec!["5".into()]);
|
||||||
@ -270,7 +281,7 @@ impl KeymapSet {
|
|||||||
normal.bind(KeyCode::Char('q'), ctrl, "force-quit");
|
normal.bind(KeyCode::Char('q'), ctrl, "force-quit");
|
||||||
normal.bind_args(
|
normal.bind_args(
|
||||||
KeyCode::Char(':'),
|
KeyCode::Char(':'),
|
||||||
shift,
|
none,
|
||||||
"enter-mode",
|
"enter-mode",
|
||||||
vec!["command".into()],
|
vec!["command".into()],
|
||||||
);
|
);
|
||||||
@ -278,24 +289,24 @@ impl KeymapSet {
|
|||||||
normal.bind(KeyCode::Char('s'), ctrl, "save");
|
normal.bind(KeyCode::Char('s'), ctrl, "save");
|
||||||
normal.bind(KeyCode::F(1), none, "enter-mode");
|
normal.bind(KeyCode::F(1), none, "enter-mode");
|
||||||
normal.bind_args(KeyCode::F(1), none, "enter-mode", vec!["help".into()]);
|
normal.bind_args(KeyCode::F(1), none, "enter-mode", vec!["help".into()]);
|
||||||
normal.bind_args(KeyCode::Char('?'), shift, "enter-mode", vec!["help".into()]);
|
normal.bind_args(KeyCode::Char('?'), none, "enter-mode", vec!["help".into()]);
|
||||||
|
|
||||||
// Panel toggles
|
// Panel toggles
|
||||||
normal.bind_args(
|
normal.bind_args(
|
||||||
KeyCode::Char('F'),
|
KeyCode::Char('F'),
|
||||||
shift,
|
none,
|
||||||
"toggle-panel-and-focus",
|
"toggle-panel-and-focus",
|
||||||
vec!["formula".into()],
|
vec!["formula".into()],
|
||||||
);
|
);
|
||||||
normal.bind_args(
|
normal.bind_args(
|
||||||
KeyCode::Char('C'),
|
KeyCode::Char('C'),
|
||||||
shift,
|
none,
|
||||||
"toggle-panel-and-focus",
|
"toggle-panel-and-focus",
|
||||||
vec!["category".into()],
|
vec!["category".into()],
|
||||||
);
|
);
|
||||||
normal.bind_args(
|
normal.bind_args(
|
||||||
KeyCode::Char('V'),
|
KeyCode::Char('V'),
|
||||||
shift,
|
none,
|
||||||
"toggle-panel-and-focus",
|
"toggle-panel-and-focus",
|
||||||
vec!["view".into()],
|
vec!["view".into()],
|
||||||
);
|
);
|
||||||
@ -332,7 +343,7 @@ impl KeymapSet {
|
|||||||
"search-navigate",
|
"search-navigate",
|
||||||
vec!["forward".into()],
|
vec!["forward".into()],
|
||||||
);
|
);
|
||||||
normal.bind(KeyCode::Char('N'), shift, "search-or-category-add");
|
normal.bind(KeyCode::Char('N'), none, "search-or-category-add");
|
||||||
|
|
||||||
// Page navigation
|
// Page navigation
|
||||||
normal.bind(KeyCode::Char(']'), none, "page-next");
|
normal.bind(KeyCode::Char(']'), none, "page-next");
|
||||||
@ -340,10 +351,10 @@ impl KeymapSet {
|
|||||||
|
|
||||||
// Group / hide
|
// Group / hide
|
||||||
normal.bind(KeyCode::Char('z'), none, "toggle-group-under-cursor");
|
normal.bind(KeyCode::Char('z'), none, "toggle-group-under-cursor");
|
||||||
normal.bind(KeyCode::Char('H'), shift, "hide-selected-row-item");
|
normal.bind(KeyCode::Char('H'), none, "hide-selected-row-item");
|
||||||
|
|
||||||
// Tile select
|
// Tile select
|
||||||
normal.bind(KeyCode::Char('T'), shift, "enter-tile-select");
|
normal.bind(KeyCode::Char('T'), none, "enter-tile-select");
|
||||||
normal.bind(KeyCode::Left, ctrl, "enter-tile-select");
|
normal.bind(KeyCode::Left, ctrl, "enter-tile-select");
|
||||||
normal.bind(KeyCode::Right, ctrl, "enter-tile-select");
|
normal.bind(KeyCode::Right, ctrl, "enter-tile-select");
|
||||||
normal.bind(KeyCode::Up, ctrl, "enter-tile-select");
|
normal.bind(KeyCode::Up, ctrl, "enter-tile-select");
|
||||||
@ -360,8 +371,8 @@ impl KeymapSet {
|
|||||||
normal.bind_prefix(KeyCode::Char('y'), none, Arc::new(y_map));
|
normal.bind_prefix(KeyCode::Char('y'), none, Arc::new(y_map));
|
||||||
|
|
||||||
let mut z_map = Keymap::new();
|
let mut z_map = Keymap::new();
|
||||||
z_map.bind(KeyCode::Char('Z'), shift, "save-and-quit");
|
z_map.bind(KeyCode::Char('Z'), none, "save-and-quit");
|
||||||
normal.bind_prefix(KeyCode::Char('Z'), shift, Arc::new(z_map));
|
normal.bind_prefix(KeyCode::Char('Z'), none, Arc::new(z_map));
|
||||||
|
|
||||||
set.insert(ModeKey::Normal, Arc::new(normal));
|
set.insert(ModeKey::Normal, Arc::new(normal));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user