From 5cd3cf3c18ca90d468356ce8c1bf840363a41e7e Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Sat, 4 Apr 2026 09:58:31 -0700 Subject: [PATCH] feat(app): add tile_cat_idx and buffers to App state Add tile_cat_idx field to track selected tile category index. Add buffers HashMap for named text buffers used in text-entry modes. Update AppMode::TileSelect to remove nested cat_idx struct. Update cmd_context to accept key and modifiers parameters. Update cmd_context to populate new fields from App state. Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M) --- src/ui/app.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/ui/app.rs b/src/ui/app.rs index e52b847..2cc8a98 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -1,17 +1,18 @@ use anyhow::Result; -use crossterm::event::{KeyCode, KeyEvent}; +use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::{Duration, Instant}; -use crate::command::cmd::{Cmd, CmdContext}; +use crate::command::cmd::CmdContext; use crate::command::keymap::{Keymap, KeymapSet}; use crate::command::{self, Command}; use crate::import::wizard::{ImportWizard, WizardStep}; use crate::model::cell::{CellKey, CellValue}; use crate::model::Model; use crate::persistence; -use crate::view::{Axis, GridLayout}; +use crate::view::GridLayout; #[derive(Debug, Clone, PartialEq)] pub enum AppMode { @@ -34,9 +35,7 @@ pub enum AppMode { buffer: String, }, ViewPanel, - TileSelect { - cat_idx: usize, - }, + TileSelect, ImportWizard, ExportPrompt { buffer: String, @@ -67,6 +66,10 @@ pub struct App { pub dirty: bool, /// Yanked cell value for `p` paste pub yanked: Option, + /// Tile select cursor (which category index is highlighted) + pub tile_cat_idx: usize, + /// Named text buffers for text-entry modes + pub buffers: HashMap, /// Transient keymap for Emacs-style prefix key sequences (g→gg, y→yy, etc.) pub transient_keymap: Option>, keymap_set: KeymapSet, @@ -91,12 +94,14 @@ impl App { formula_cursor: 0, dirty: false, yanked: None, + tile_cat_idx: 0, + buffers: HashMap::new(), transient_keymap: None, keymap_set: KeymapSet::default_keymaps(), } } - fn cmd_context(&self) -> CmdContext { + fn cmd_context(&self, key: KeyCode, mods: KeyModifiers) -> CmdContext<'_> { let view = self.model.active_view(); CmdContext { model: &self.model, @@ -108,9 +113,17 @@ impl App { 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, view_panel_open: self.view_panel_open, + buffers: &self.buffers, + formula_cursor: self.formula_cursor, + cat_panel_cursor: self.cat_panel_cursor, + view_panel_cursor: self.view_panel_cursor, + tile_cat_idx: self.tile_cat_idx, + key_code: key, + key_modifiers: mods, } } @@ -1098,7 +1111,7 @@ mod tests { } fn run_cmd(app: &mut App, cmd: &dyn crate::command::cmd::Cmd) { - let ctx = app.cmd_context(); + let ctx = app.cmd_context(KeyCode::Null, KeyModifiers::NONE); let effects = cmd.execute(&ctx); drop(ctx); app.apply_effects(effects);