update CmdContext and imports

- Updated imports to include Panel and Axis.
- Added new fields to CmdContext: formula_panel_open, category_panel_open,
  view_panel_open.
- Reformatted effect vectors for consistency.
- Minor formatting changes to improve readability.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (gpt-oss:20b)
This commit is contained in:
Edward Langley
2026-04-04 09:31:48 -07:00
parent 038c99c473
commit f2bb8ec2a7

View File

@ -3,8 +3,8 @@ use std::fmt::Debug;
use crate::model::cell::CellValue; use crate::model::cell::CellValue;
use crate::model::Model; use crate::model::Model;
use crate::ui::app::AppMode; use crate::ui::app::AppMode;
use crate::ui::effect::{self, Effect}; use crate::ui::effect::{self, Effect, Panel};
use crate::view::GridLayout; use crate::view::{Axis, AxisEntry, GridLayout};
/// Read-only context available to commands for decision-making. /// Read-only context available to commands for decision-making.
pub struct CmdContext<'a> { pub struct CmdContext<'a> {
@ -15,9 +15,11 @@ pub struct CmdContext<'a> {
pub col_offset: usize, pub col_offset: usize,
pub search_query: &'a str, pub search_query: &'a str,
pub yanked: &'a Option<CellValue>, pub yanked: &'a Option<CellValue>,
pub pending_key: Option<char>,
pub dirty: bool, pub dirty: bool,
pub file_path_set: bool, pub file_path_set: bool,
pub formula_panel_open: bool,
pub category_panel_open: bool,
pub view_panel_open: bool,
} }
/// A command that reads state and produces effects. /// A command that reads state and produces effects.
@ -97,9 +99,8 @@ impl Cmd for JumpToLastRow {
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> { fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let layout = GridLayout::new(ctx.model, ctx.model.active_view()); let layout = GridLayout::new(ctx.model, ctx.model.active_view());
let last = layout.row_count().saturating_sub(1); let last = layout.row_count().saturating_sub(1);
let mut effects: Vec<Box<dyn Effect>> = vec![ let mut effects: Vec<Box<dyn Effect>> =
Box::new(effect::SetSelected(last, ctx.selected.1)), vec![Box::new(effect::SetSelected(last, ctx.selected.1))];
];
if last >= ctx.row_offset + 20 { if last >= ctx.row_offset + 20 {
effects.push(Box::new(effect::SetRowOffset(last.saturating_sub(19)))); effects.push(Box::new(effect::SetRowOffset(last.saturating_sub(19))));
} }
@ -130,9 +131,8 @@ impl Cmd for JumpToLastCol {
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> { fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let layout = GridLayout::new(ctx.model, ctx.model.active_view()); let layout = GridLayout::new(ctx.model, ctx.model.active_view());
let last = layout.col_count().saturating_sub(1); let last = layout.col_count().saturating_sub(1);
let mut effects: Vec<Box<dyn Effect>> = vec![ let mut effects: Vec<Box<dyn Effect>> =
Box::new(effect::SetSelected(ctx.selected.0, last)), vec![Box::new(effect::SetSelected(ctx.selected.0, last))];
];
if last >= ctx.col_offset + 8 { if last >= ctx.col_offset + 8 {
effects.push(Box::new(effect::SetColOffset(last.saturating_sub(7)))); effects.push(Box::new(effect::SetColOffset(last.saturating_sub(7))));
} }
@ -150,9 +150,8 @@ impl Cmd for ScrollRows {
let layout = GridLayout::new(ctx.model, ctx.model.active_view()); let layout = GridLayout::new(ctx.model, ctx.model.active_view());
let row_max = layout.row_count().saturating_sub(1) as i32; let row_max = layout.row_count().saturating_sub(1) as i32;
let nr = (ctx.selected.0 as i32 + self.0).clamp(0, row_max) as usize; let nr = (ctx.selected.0 as i32 + self.0).clamp(0, row_max) as usize;
let mut effects: Vec<Box<dyn Effect>> = vec![ let mut effects: Vec<Box<dyn Effect>> =
Box::new(effect::SetSelected(nr, ctx.selected.1)), vec![Box::new(effect::SetSelected(nr, ctx.selected.1))];
];
let mut row_offset = ctx.row_offset; let mut row_offset = ctx.row_offset;
if nr < row_offset { if nr < row_offset {
row_offset = nr; row_offset = nr;
@ -215,10 +214,7 @@ impl Cmd for SaveAndQuit {
"save-and-quit" "save-and-quit"
} }
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> { fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
vec![ vec![Box::new(effect::Save), effect::change_mode(AppMode::Quit)]
Box::new(effect::Save),
effect::change_mode(AppMode::Quit),
]
} }
} }