From 399bc5a79f42806cdffd9c403f20105dceb62da1 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 25 Oct 2026 03:32:41 +0000 Subject: [PATCH] Integration: editing text in a table cell ends a selected cell range --- crates/engine/src/cmd/text.rs | 2 ++ crates/engine/src/tests.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs index 09229f4b..4ee98fa7 100644 --- a/crates/engine/src/cmd/text.rs +++ b/crates/engine/src/cmd/text.rs @@ -339,6 +339,7 @@ fn edit(s: &mut Session, p: &Value) -> Result { s.select(|_, sel| { sel.text = Some(TextSel { notes: true, anchor: end, caret: end, ..Default::default() }); sel.shapes.clear(); + sel.cells = None; })?; return ok(); } @@ -369,6 +370,7 @@ fn edit(s: &mut Session, p: &Value) -> Result { s.select(|_, sel| { sel.shapes = vec![id]; sel.text = Some(TextSel { shape: id, anchor: at, caret: at, cell, notes: false, line_end: None }); + sel.cells = None; })?; Ok(json!({"id": id, "at": [at.0, at.1]})) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 7f49cd3f..b7371fd2 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -842,6 +842,25 @@ fn clicks_while_editing_a_cell_move_the_caret_between_cells() { assert!(text_sel(&s).is_none()); } +/// Editing text in a cell ends a selected cell range, so Delete after leaving the text deletes the +/// table rather than clearing the cells of the old range. +#[test] +fn editing_a_cell_ends_the_selected_cell_range() { + let mut s = session(); + let id = table_at(&mut s, &[100.0, 100.0], json!([["a", "b"], ["c", "d"]])); + s.execute("table.selectCells", &json!({"id": id, "from": [0, 0], "to": [0, 1]})).unwrap(); + s.execute("text.edit", &json!({"id": id, "cell": [1, 1]})).unwrap(); + assert_eq!(s.doc().unwrap().selection.cells, None); + s.execute("table.selectCells", &json!({"id": id, "from": [0, 0], "to": [0, 1]})).unwrap(); + s.execute("text.edit", &json!({"notes": true})).unwrap(); + s.execute("text.exit", &json!({})).unwrap(); + assert_eq!(s.doc().unwrap().selection.cells, None); + s.execute("text.edit", &json!({"id": id, "cell": [1, 1]})).unwrap(); + s.execute("text.exit", &json!({})).unwrap(); + s.execute("edit.delete", &json!({})).unwrap(); + assert!(s.doc().unwrap().shape(id).is_none(), "the table is deleted"); +} + #[test] fn dragging_across_cells_selects_a_range_of_cells() { let mut s = session();