Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Integration: #1674 text.move leaves the selected cells, so typing inserts at the caret

aiongg2ecb85ff9792
diff --git a/crates/engine/src/cmd/text/caret.rs b/crates/engine/src/cmd/text/caret.rs
index 670de4049..0621e30de 100644
--- a/crates/engine/src/cmd/text/caret.rs
+++ b/crates/engine/src/cmd/text/caret.rs
@@ -380,6 +380,8 @@ pub(super) fn move_caret(s: &mut Session, p: &Value) -> Result<Value> {
s.typing_format = None;
let stm = s.doc_mut()?;
stm.selection.text = Some(if extend { TextSel { focus: new, ..t } } else { TextSel { anchor: new, focus: new, ..t } });
+ // Moving the caret leaves the selected cells, so typing inserts at the caret.
+ stm.selection.cells = None;
stm.bump_revision();
Ok(json!({"pos": new}))
}
diff --git a/crates/engine/src/tests/table.rs b/crates/engine/src/tests/table.rs
index 45e4b8db8..770581fa6 100644
--- a/crates/engine/src/tests/table.rs
+++ b/crates/engine/src/tests/table.rs
@@ -176,6 +176,12 @@ fn escape_toggles_text_and_cell_selection() {
let sel = s.doc().unwrap().selection.clone();
assert!(sel.cells.is_none());
assert_eq!(sel.text.unwrap().range(), 3..3);
+ // Moving the caret leaves the cell selection: typing inserts at the caret, not over the cell.
+ s.execute("table.toggleSelection", &json!({})).unwrap();
+ s.execute("text.move", &json!({"dir": "right"})).unwrap();
+ assert!(s.doc().unwrap().selection.cells.is_none());
+ s.execute("text.insert", &json!({"text": "!"})).unwrap();
+ assert_eq!(s.execute("table.get", &json!({"table": tid})).unwrap()["cells"][1]["text"], "F!ax");
// A selection that starts inside a merged cell goes back to the merged cell's text.
s.execute("table.select", &json!({"rows": [0, 1], "cols": [0, 0]})).unwrap();
s.execute("table.merge", &json!({})).unwrap();