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:
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
use crossterm::event::KeyCode;
|
||||||
|
|
||||||
use crate::model::cell::CellValue;
|
use crate::model::cell::CellValue;
|
||||||
use crate::model::Model;
|
use crate::model::Model;
|
||||||
@ -19,7 +19,6 @@ pub struct CmdContext<'a> {
|
|||||||
pub search_query: &'a str,
|
pub search_query: &'a str,
|
||||||
pub yanked: &'a Option<CellValue>,
|
pub yanked: &'a Option<CellValue>,
|
||||||
pub dirty: bool,
|
pub dirty: bool,
|
||||||
pub file_path_set: bool,
|
|
||||||
pub search_mode: bool,
|
pub search_mode: bool,
|
||||||
pub formula_panel_open: bool,
|
pub formula_panel_open: bool,
|
||||||
pub category_panel_open: bool,
|
pub category_panel_open: bool,
|
||||||
@ -39,12 +38,14 @@ pub struct CmdContext<'a> {
|
|||||||
pub col_count: usize,
|
pub col_count: usize,
|
||||||
/// The key that triggered this command
|
/// The key that triggered this command
|
||||||
pub key_code: KeyCode,
|
pub key_code: KeyCode,
|
||||||
pub key_modifiers: KeyModifiers,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A command that reads state and produces effects.
|
/// A command that reads state and produces effects.
|
||||||
pub trait Cmd: Debug + Send + Sync {
|
pub trait Cmd: Debug + Send + Sync {
|
||||||
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>>;
|
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;
|
fn name(&self) -> &str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +136,7 @@ impl CmdRegistry {
|
|||||||
Err(format!("Unknown command: {name}"))
|
Err(format!("Unknown command: {name}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn names(&self) -> impl Iterator<Item = &'static str> + '_ {
|
pub fn names(&self) -> impl Iterator<Item = &'static str> + '_ {
|
||||||
self.entries.iter().map(|e| e.name)
|
self.entries.iter().map(|e| e.name)
|
||||||
}
|
}
|
||||||
@ -2408,7 +2410,6 @@ mod tests {
|
|||||||
search_query: "",
|
search_query: "",
|
||||||
yanked: &None,
|
yanked: &None,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
file_path_set: false,
|
|
||||||
search_mode: false,
|
search_mode: false,
|
||||||
formula_panel_open: false,
|
formula_panel_open: false,
|
||||||
category_panel_open: false,
|
category_panel_open: false,
|
||||||
@ -2422,7 +2423,6 @@ mod tests {
|
|||||||
row_count: layout.row_count(),
|
row_count: layout.row_count(),
|
||||||
col_count: layout.col_count(),
|
col_count: layout.col_count(),
|
||||||
key_code: KeyCode::Null,
|
key_code: KeyCode::Null,
|
||||||
key_modifiers: KeyModifiers::NONE,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -193,10 +193,6 @@ impl KeymapSet {
|
|||||||
self.mode_maps.insert(mode, keymap);
|
self.mode_maps.insert(mode, keymap);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registry(&self) -> &CmdRegistry {
|
|
||||||
&self.registry
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Dispatch a key event: returns effects if a binding matched.
|
/// Dispatch a key event: returns effects if a binding matched.
|
||||||
pub fn dispatch(
|
pub fn dispatch(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@ -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 view = self.model.active_view();
|
||||||
let layout = GridLayout::new(&self.model, view);
|
let layout = GridLayout::new(&self.model, view);
|
||||||
let (sel_row, sel_col) = view.selected;
|
let (sel_row, sel_col) = view.selected;
|
||||||
@ -113,7 +113,6 @@ impl App {
|
|||||||
search_query: &self.search_query,
|
search_query: &self.search_query,
|
||||||
yanked: &self.yanked,
|
yanked: &self.yanked,
|
||||||
dirty: self.dirty,
|
dirty: self.dirty,
|
||||||
file_path_set: self.file_path.is_some(),
|
|
||||||
search_mode: self.search_mode,
|
search_mode: self.search_mode,
|
||||||
formula_panel_open: self.formula_panel_open,
|
formula_panel_open: self.formula_panel_open,
|
||||||
category_panel_open: self.category_panel_open,
|
category_panel_open: self.category_panel_open,
|
||||||
@ -127,7 +126,6 @@ impl App {
|
|||||||
row_count: layout.row_count(),
|
row_count: layout.row_count(),
|
||||||
col_count: layout.col_count(),
|
col_count: layout.col_count(),
|
||||||
key_code: key,
|
key_code: key,
|
||||||
key_modifiers: mods,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user