selection.move: Ctrl+arrow without a direction stays put

jump() searched for the next filled cell by stepping (dr, dc); with
neither set, the step never moved, so selection.move {"jump":true}
from a blank cell of a sheet with content looped forever (found with
an agent call that left out dr and dc). It now returns the cell it
started from.
This commit is contained in:
nihilist-narwhal 2026-10-10 02:20:21 -05:00
parent 13664fe66b
commit 439df2ae3a
1 changed files with 6 additions and 0 deletions

View File

@ -119,6 +119,10 @@ impl Selection {
/// Ctrl+arrow: jump to the edge of the current data region (Excel's End mode).
pub fn jump(sheet: &Sheet, from: CellRef, dr: i64, dc: i64) -> CellRef {
if dr == 0 && dc == 0 {
// No direction: nowhere to go (the search below would never advance).
return from;
}
let filled = |c: CellRef| sheet.value_ref(c).is_some_and(|v| !v.is_empty());
let Some(mut cur) = from.offset(dr, dc) else { return from };
let here = filled(from);
@ -222,6 +226,8 @@ mod tests {
}
s.set_value(CellRef::new(10, 0), Value::Number(1.0));
assert_eq!(jump(&s, CellRef::new(0, 0), 1, 0), CellRef::new(4, 0));
// Without a direction it stays put (it used to loop forever from a blank cell).
assert_eq!(jump(&s, CellRef::new(7, 0), 0, 0), CellRef::new(7, 0));
assert_eq!(jump(&s, CellRef::new(4, 0), 1, 0), CellRef::new(10, 0));
assert_eq!(jump(&s, CellRef::new(10, 0), 1, 0), CellRef::new(MAX_ROWS - 1, 0));
assert_eq!(jump(&s, CellRef::new(0, 0), 0, 1), CellRef::new(0, MAX_COLS - 1));