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)
This commit is contained in:
Edward Langley
2026-04-06 15:09:58 -07:00
parent ad95bc34a9
commit 121b7d2dd7

View File

@ -267,21 +267,25 @@ fn viewport_effects(
nc: usize, nc: usize,
old_row_offset: usize, old_row_offset: usize,
old_col_offset: usize, old_col_offset: usize,
visible_rows: usize,
visible_cols: usize,
) -> Vec<Box<dyn Effect>> { ) -> Vec<Box<dyn Effect>> {
let mut effects: Vec<Box<dyn Effect>> = vec![effect::set_selected(nr, nc)]; let mut effects: Vec<Box<dyn Effect>> = vec![effect::set_selected(nr, nc)];
let mut row_offset = old_row_offset; let mut row_offset = old_row_offset;
let mut col_offset = old_col_offset; let mut col_offset = old_col_offset;
let vr = visible_rows.max(1);
let vc = visible_cols.max(1);
if nr < row_offset { if nr < row_offset {
row_offset = nr; row_offset = nr;
} }
if nr >= row_offset + 20 { if nr >= row_offset + vr {
row_offset = nr.saturating_sub(19); row_offset = nr.saturating_sub(vr - 1);
} }
if nc < col_offset { if nc < col_offset {
col_offset = nc; col_offset = nc;
} }
if nc >= col_offset + 8 { if nc >= col_offset + vc {
col_offset = nc.saturating_sub(7); col_offset = nc.saturating_sub(vc - 1);
} }
if row_offset != old_row_offset { if row_offset != old_row_offset {
effects.push(Box::new(effect::SetRowOffset(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 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 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; 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 { } else {
(r, c) // already at bottom-right; stay (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, col_count: 0,
row_offset: 0, row_offset: 0,
col_offset: 0, col_offset: 0,
visible_rows: 20,
visible_cols: 8,
}, },
})) }))
}, },
@ -2539,6 +2545,8 @@ pub fn default_registry() -> CmdRegistry {
col_count: 0, col_count: 0,
row_offset: 0, row_offset: 0,
col_offset: 0, col_offset: 0,
visible_rows: 20,
visible_cols: 8,
}, },
})) }))
}, },
@ -2562,6 +2570,8 @@ pub fn default_registry() -> CmdRegistry {
col_count: 0, col_count: 0,
row_offset: 0, row_offset: 0,
col_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::<i32>().map_err(|e| e.to_string())?; let delta = args[1].parse::<i32>().map_err(|e| e.to_string())?;
let (current, max) = match panel { let (current, max) = match panel {
Panel::Formula => (ctx.formula_cursor, ctx.model.formulas().len()), 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()), Panel::View => (ctx.view_panel_cursor, ctx.model.views.len()),
}; };
Ok(Box::new(MovePanelCursor { Ok(Box::new(MovePanelCursor {