From 5e5b5d082dc50f5f0508742f087e15d916ee2eac Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 8 Nov 2026 23:22:22 +0100 Subject: [PATCH] fix(selection): Enter from a merged cell keeps the Tab run's column Leaving a merged cell downwards kept the start column and dropped the column offset Enter passes to return to the Tab run's start column, so Tab A2 -> B2:C3, Enter landed on B4 instead of A4. Keep the computed column (and the computed row when leaving to the right). Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/edit/selection.rs | 4 ++-- crates/ui-egui/src/app/editing.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/edit/selection.rs b/crates/engine/src/cmd/edit/selection.rs index 6d1625f03..e59f59394 100644 --- a/crates/engine/src/cmd/edit/selection.rs +++ b/crates/engine/src/cmd/edit/selection.rs @@ -85,9 +85,9 @@ pub(super) fn selection_move(s: &mut Session, p: &Json) -> Result { if !extend && let Some(m) = sheet.merge_at(from) { // Leaving a merged cell moves from its edge. if dr > 0 { - t = CellRef::new(m.end.offset_clamped(dr, 0).row, from.col); + t = CellRef::new(m.end.offset_clamped(dr, 0).row, t.col); } else if dc > 0 { - t = CellRef::new(from.row, m.end.offset_clamped(0, dc).col); + t = CellRef::new(t.row, m.end.offset_clamped(0, dc).col); } } let mut guard = 0; diff --git a/crates/ui-egui/src/app/editing.rs b/crates/ui-egui/src/app/editing.rs index 92689eb4f..c2333caee 100644 --- a/crates/ui-egui/src/app/editing.rs +++ b/crates/ui-egui/src/app/editing.rs @@ -537,5 +537,13 @@ mod merged_cell_enter_tests { assert_eq!(sel(&app), "D2"); app.move_after_enter(1, 0); assert_eq!(sel(&app), "A3"); + // Enter straight from the merged cell in a Tab run leaves it below its bottom edge and + // still goes back to the run's start column. + app.tab_run = None; + app.run("selection.set", json!({"cell": "A2"})).unwrap(); + app.move_after_enter(0, 1); + assert_eq!(sel(&app), "B2:C3"); + app.move_after_enter(1, 0); + assert_eq!(sel(&app), "A4"); } }