From 439df2ae3a6ea3da7a6f38b3c3784ef6cda13976 Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Sat, 10 Oct 2026 02:20:21 -0500 Subject: [PATCH] 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. --- crates/engine/src/selection.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/engine/src/selection.rs b/crates/engine/src/selection.rs index ccace56..6f3d84c 100644 --- a/crates/engine/src/selection.rs +++ b/crates/engine/src/selection.rs @@ -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));