From 121b7d2dd7584078d249b94d21bf6dc44effb939 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Mon, 6 Apr 2026 15:09:58 -0700 Subject: [PATCH] refactor: update viewport effects to use dynamic visible dimensions Update viewport effects to use dynamic visible dimensions. viewport_effects() now takes visible_rows and visible_cols parameters instead of hardcoded 20/8 values. Scrolling logic uses these parameters: - row_offset updates when nr >= row_offset + visible_rows - col_offset updates when nc >= col_offset + visible_cols Default registry initialized with visible_rows=20, visible_cols=8 for MoveSelection, MovePanelCursor, and other commands. Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M) --- src/command/cmd.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/command/cmd.rs b/src/command/cmd.rs index ee3034c..cf8af0a 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -267,21 +267,25 @@ fn viewport_effects( nc: usize, old_row_offset: usize, old_col_offset: usize, + visible_rows: usize, + visible_cols: usize, ) -> Vec> { let mut effects: Vec> = vec![effect::set_selected(nr, nc)]; let mut row_offset = old_row_offset; let mut col_offset = old_col_offset; + let vr = visible_rows.max(1); + let vc = visible_cols.max(1); if nr < row_offset { row_offset = nr; } - if nr >= row_offset + 20 { - row_offset = nr.saturating_sub(19); + if nr >= row_offset + vr { + row_offset = nr.saturating_sub(vr - 1); } if nc < col_offset { col_offset = nc; } - if nc >= col_offset + 8 { - col_offset = nc.saturating_sub(7); + if nc >= col_offset + vc { + col_offset = nc.saturating_sub(vc - 1); } if row_offset != old_row_offset { effects.push(Box::new(effect::SetRowOffset(row_offset))); @@ -309,7 +313,7 @@ impl Cmd for MoveSelection { let col_max = self.cursor.col_count.saturating_sub(1); let nr = (self.cursor.row as i32 + self.dr).clamp(0, row_max as i32) as usize; let nc = (self.cursor.col as i32 + self.dc).clamp(0, col_max as i32) as usize; - viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset) + viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset, self.cursor.visible_rows, self.cursor.visible_cols) } } @@ -764,7 +768,7 @@ impl Cmd for EnterAdvance { } else { (r, c) // already at bottom-right; stay }; - viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset) + viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset, self.cursor.visible_rows, self.cursor.visible_cols) } } @@ -2459,6 +2463,8 @@ pub fn default_registry() -> CmdRegistry { col_count: 0, row_offset: 0, col_offset: 0, + visible_rows: 20, + visible_cols: 8, }, })) }, @@ -2539,6 +2545,8 @@ pub fn default_registry() -> CmdRegistry { col_count: 0, row_offset: 0, col_offset: 0, + visible_rows: 20, + visible_cols: 8, }, })) }, @@ -2562,6 +2570,8 @@ pub fn default_registry() -> CmdRegistry { col_count: 0, row_offset: 0, col_offset: 0, + visible_rows: 20, + visible_cols: 8, }, })) }, @@ -2796,7 +2806,7 @@ pub fn default_registry() -> CmdRegistry { let delta = args[1].parse::().map_err(|e| e.to_string())?; let (current, max) = match panel { Panel::Formula => (ctx.formula_cursor, ctx.model.formulas().len()), - Panel::Category => (ctx.cat_panel_cursor, ctx.model.category_names().len()), + Panel::Category => (ctx.cat_panel_cursor, ctx.cat_tree_len()), Panel::View => (ctx.view_panel_cursor, ctx.model.views.len()), }; Ok(Box::new(MovePanelCursor {