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

This commit is contained in:
aiongg
2026-10-30 21:29:34 +00:00
parent 0ca30e1408
commit 2ecb85ff97
2 changed files with 8 additions and 0 deletions
+2
View File
@@ -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}))
}
+6
View File
@@ -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();