From 30383f203ec7c75bd6e6c91ab800b1b8aa9ddc66 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Wed, 15 Apr 2026 22:44:13 -0700 Subject: [PATCH] refactor(keymap): pass mode arguments in keybindings Update keybindings for normal, records-normal, editing, and records-editing modes to pass the appropriate mode names as arguments to the parameterized commands. This ensures that the correct mode is entered when using commands like `edit-or-drill` , `enter-edit-at-cursor` , `commit-cell-edit` , and `commit-and-advance-right` . Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-26B-A4B-it-UD-Q5_K_XL.gguf) --- src/command/keymap.rs | 60 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/command/keymap.rs b/src/command/keymap.rs index a0276e3..92d5870 100644 --- a/src/command/keymap.rs +++ b/src/command/keymap.rs @@ -431,9 +431,21 @@ impl KeymapSet { ); normal.bind(KeyCode::Tab, none, "cycle-panel-focus"); - // Editing entry — i/a drill into aggregated cells, else edit - normal.bind(KeyCode::Char('i'), none, "edit-or-drill"); - normal.bind(KeyCode::Char('a'), none, "edit-or-drill"); + // Editing entry — i/a drill into aggregated cells, else edit. + // The mode arg controls which editing mode is entered; records-normal + // overrides these to "records-editing" via its own bindings. + normal.bind_args( + KeyCode::Char('i'), + none, + "edit-or-drill", + vec!["editing".into()], + ); + normal.bind_args( + KeyCode::Char('a'), + none, + "edit-or-drill", + vec!["editing".into()], + ); normal.bind(KeyCode::Enter, none, "enter-advance"); normal.bind(KeyCode::Char('e'), ctrl, "enter-export-prompt"); @@ -488,10 +500,27 @@ impl KeymapSet { // ── Records normal mode (inherits from normal) ──────────────────── let mut rn = Keymap::with_parent(normal); + // Override i/a so the edit branch produces records-editing mode + // instead of inheriting the normal-mode "editing" arg. + rn.bind_args( + KeyCode::Char('i'), + none, + "edit-or-drill", + vec!["records-editing".into()], + ); + rn.bind_args( + KeyCode::Char('a'), + none, + "edit-or-drill", + vec!["records-editing".into()], + ); rn.bind_seq( KeyCode::Char('o'), none, - vec![("add-record-row", vec![]), ("enter-edit-at-cursor", vec![])], + vec![ + ("add-record-row", vec![]), + ("enter-edit-at-cursor", vec!["records-editing".into()]), + ], ); set.insert(ModeKey::RecordsNormal, Arc::new(rn)); @@ -736,6 +765,8 @@ impl KeymapSet { set.insert(ModeKey::TileSelect, Arc::new(ts)); // ── Editing mode ───────────────────────────────────────────────── + // commit-* takes the target edit-mode arg so the command stays + // mode-agnostic; records-editing overrides Enter/Tab below. let mut ed = Keymap::new(); ed.bind_seq( KeyCode::Esc, @@ -749,7 +780,7 @@ impl KeymapSet { KeyCode::Enter, none, vec![ - ("commit-cell-edit", vec![]), + ("commit-cell-edit", vec!["editing".into()]), ("clear-buffer", vec!["edit".into()]), ], ); @@ -757,7 +788,7 @@ impl KeymapSet { KeyCode::Tab, none, vec![ - ("commit-and-advance-right", vec![]), + ("commit-and-advance-right", vec!["editing".into()]), ("clear-buffer", vec!["edit".into()]), ], ); @@ -767,6 +798,7 @@ impl KeymapSet { set.insert(ModeKey::Editing, ed.clone()); // ── Records editing mode (inherits from editing) ────────────────── + // Override Enter/Tab so the post-commit re-enter targets records-editing. let mut re = Keymap::with_parent(ed); re.bind_seq( KeyCode::Esc, @@ -776,6 +808,22 @@ impl KeymapSet { ("enter-mode", vec!["records-normal".into()]), ], ); + re.bind_seq( + KeyCode::Enter, + none, + vec![ + ("commit-cell-edit", vec!["records-editing".into()]), + ("clear-buffer", vec!["edit".into()]), + ], + ); + re.bind_seq( + KeyCode::Tab, + none, + vec![ + ("commit-and-advance-right", vec!["records-editing".into()]), + ("clear-buffer", vec!["edit".into()]), + ], + ); set.insert(ModeKey::RecordsEditing, Arc::new(re)); // ── Formula edit ─────────────────────────────────────────────────