refactor(command): remove key_modifiers from CmdContext

Remove the key_modifiers field from CmdContext struct and all its usages.

This simplifies the command context by removing unused modifier state.
The Cmd trait's execute method no longer receives key modifiers.

Changes:
- Removed KeyModifiers import from cmd.rs
- Removed key_modifiers field from CmdContext struct
- Removed file_path_set field from CmdContext (unused)
- Updated App::cmd_context to not populate key_modifiers
- Removed KeymapSet::registry() accessor
- Updated test code to match new struct layout
- Added documentation to Cmd::name() method

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M)
This commit is contained in:
Edward Langley
2026-04-04 12:40:55 -07:00
parent c6c8ac2c69
commit e2ff9cf98e
3 changed files with 6 additions and 12 deletions

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fmt::Debug;
use crossterm::event::{KeyCode, KeyModifiers};
use crossterm::event::KeyCode;
use crate::model::cell::CellValue;
use crate::model::Model;
@ -19,7 +19,6 @@ pub struct CmdContext<'a> {
pub search_query: &'a str,
pub yanked: &'a Option<CellValue>,
pub dirty: bool,
pub file_path_set: bool,
pub search_mode: bool,
pub formula_panel_open: bool,
pub category_panel_open: bool,
@ -39,12 +38,14 @@ pub struct CmdContext<'a> {
pub col_count: usize,
/// The key that triggered this command
pub key_code: KeyCode,
pub key_modifiers: KeyModifiers,
}
/// A command that reads state and produces effects.
pub trait Cmd: Debug + Send + Sync {
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>>;
/// The canonical name of this command (matches its registry key).
/// Used by the parser tests and for introspection.
#[allow(dead_code)]
fn name(&self) -> &str;
}
@ -135,6 +136,7 @@ impl CmdRegistry {
Err(format!("Unknown command: {name}"))
}
#[allow(dead_code)]
pub fn names(&self) -> impl Iterator<Item = &'static str> + '_ {
self.entries.iter().map(|e| e.name)
}
@ -2408,7 +2410,6 @@ mod tests {
search_query: "",
yanked: &None,
dirty: false,
file_path_set: false,
search_mode: false,
formula_panel_open: false,
category_panel_open: false,
@ -2422,7 +2423,6 @@ mod tests {
row_count: layout.row_count(),
col_count: layout.col_count(),
key_code: KeyCode::Null,
key_modifiers: KeyModifiers::NONE,
}
}

View File

@ -193,10 +193,6 @@ impl KeymapSet {
self.mode_maps.insert(mode, keymap);
}
pub fn registry(&self) -> &CmdRegistry {
&self.registry
}
/// Dispatch a key event: returns effects if a binding matched.
pub fn dispatch(
&self,

View File

@ -100,7 +100,7 @@ impl App {
}
}
pub fn cmd_context(&self, key: KeyCode, mods: KeyModifiers) -> CmdContext<'_> {
pub fn cmd_context(&self, key: KeyCode, _mods: KeyModifiers) -> CmdContext<'_> {
let view = self.model.active_view();
let layout = GridLayout::new(&self.model, view);
let (sel_row, sel_col) = view.selected;
@ -113,7 +113,6 @@ impl App {
search_query: &self.search_query,
yanked: &self.yanked,
dirty: self.dirty,
file_path_set: self.file_path.is_some(),
search_mode: self.search_mode,
formula_panel_open: self.formula_panel_open,
category_panel_open: self.category_panel_open,
@ -127,7 +126,6 @@ impl App {
row_count: layout.row_count(),
col_count: layout.col_count(),
key_code: key,
key_modifiers: mods,
}
}