diff --git a/src/command/cmd.rs b/src/command/cmd.rs index 5400b52..3527931 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -1,5 +1,8 @@ +use std::collections::HashMap; use std::fmt::Debug; +use crossterm::event::{KeyCode, KeyModifiers}; + use crate::model::cell::CellValue; use crate::model::Model; use crate::ui::app::AppMode; @@ -17,9 +20,21 @@ pub struct CmdContext<'a> { pub yanked: &'a Option, pub dirty: bool, pub file_path_set: bool, + pub search_mode: bool, pub formula_panel_open: bool, pub category_panel_open: bool, pub view_panel_open: bool, + /// Panel cursors + pub formula_cursor: usize, + pub cat_panel_cursor: usize, + pub view_panel_cursor: usize, + /// Tile select cursor (which category is selected) + pub tile_cat_idx: usize, + /// Named text buffers + pub buffers: &'a HashMap, + /// The key that triggered this command + pub key_code: KeyCode, + pub key_modifiers: KeyModifiers, } /// A command that reads state and produces effects. diff --git a/src/draw.rs b/src/draw.rs index e505487..2f6d806 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -251,7 +251,7 @@ fn draw_content(f: &mut Frame, area: Rect, app: &App) { } fn draw_tile_bar(f: &mut Frame, area: Rect, app: &App) { - f.render_widget(TileBar::new(&app.model, &app.mode), area); + f.render_widget(TileBar::new(&app.model, &app.mode, app.tile_cat_idx), area); } fn draw_bottom_bar(f: &mut Frame, area: Rect, app: &App) { diff --git a/src/ui/effect.rs b/src/ui/effect.rs index 01ef0dd..0a7e435 100644 --- a/src/ui/effect.rs +++ b/src/ui/effect.rs @@ -281,6 +281,26 @@ impl Effect for SetSearchMode { } } +/// Set a named buffer's contents. +#[derive(Debug)] +pub struct SetBuffer { + pub name: String, + pub value: String, +} +impl Effect for SetBuffer { + fn apply(&self, app: &mut App) { + app.buffers.insert(self.name.clone(), self.value.clone()); + } +} + +#[derive(Debug)] +pub struct SetTileCatIdx(pub usize); +impl Effect for SetTileCatIdx { + fn apply(&self, app: &mut App) { + app.tile_cat_idx = self.0; + } +} + // ── Side effects ───────────────────────────────────────────────────────────── #[derive(Debug)] diff --git a/src/ui/tile_bar.rs b/src/ui/tile_bar.rs index 12d58b5..34f4a25 100644 --- a/src/ui/tile_bar.rs +++ b/src/ui/tile_bar.rs @@ -21,11 +21,12 @@ fn axis_display(axis: Axis) -> (&'static str, Color) { pub struct TileBar<'a> { pub model: &'a Model, pub mode: &'a AppMode, + pub tile_cat_idx: usize, } impl<'a> TileBar<'a> { - pub fn new(model: &'a Model, mode: &'a AppMode) -> Self { - Self { model, mode } + pub fn new(model: &'a Model, mode: &'a AppMode, tile_cat_idx: usize) -> Self { + Self { model, mode, tile_cat_idx } } } @@ -33,8 +34,8 @@ impl<'a> Widget for TileBar<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let view = self.model.active_view(); - let selected_cat_idx = if let AppMode::TileSelect { cat_idx } = self.mode { - Some(*cat_idx) + let selected_cat_idx = if matches!(self.mode, AppMode::TileSelect) { + Some(self.tile_cat_idx) } else { None };