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"); } }