Apply review fixes

- crates/model/src/edit.rs
- crates/engine/src/tests.rs
This commit is contained in:
aiongg
2026-11-08 07:34:41 +00:00
parent 3e2dc9ca7f
commit 5a2cab9483
2 changed files with 18 additions and 6 deletions
+11
View File
@@ -112,6 +112,17 @@ fn forward_delete_removes_whole_grapheme_cluster() {
let t = s.execute("text.get", &json!({"id": title})).unwrap();
assert_eq!(t["text"], rest);
}
// Inside a cluster, Delete stops at that cluster's end and leaves the next flag intact.
let mut s = session();
let title = s.doc().unwrap().current_slide().unwrap().shapes[0].id.0;
s.execute("text.edit", &json!({"id": title})).unwrap();
s.execute("text.selectAll", &json!({})).unwrap();
s.execute("text.insert", &json!({"text": "\u{1F1FA}\u{1F1F8}\u{1F1E8}\u{1F1E6}"})).unwrap();
s.execute("text.move", &json!({"to": "start"})).unwrap();
s.execute("text.move", &json!({"to": "right"})).unwrap();
s.execute("text.delete", &json!({"dir": "forward"})).unwrap();
let t = s.execute("text.get", &json!({"id": title})).unwrap();
assert_eq!(t["text"], "\u{1F1FA}\u{1F1E8}\u{1F1E6}");
}
/// `text.set` treats CRLF (or a lone CR) as one paragraph break and keeps no `\r` in the text.
+7 -6
View File
@@ -424,14 +424,15 @@ fn smart_space(body: &mut TextBody, at: Pos) -> Pos {
pub fn cluster_end(body: &TextBody, pos: Pos) -> Pos {
let (pi, ch) = clamp(body, pos);
let text = body.paragraphs.get(pi).map(Paragraph::text).unwrap_or_default();
match text.chars().nth(ch) {
Some(_) => {
let rest: String = text.chars().skip(ch).collect();
let n = rest.graphemes(true).next().map_or(1, |g| g.chars().count());
(pi, ch + n)
// Boundaries come from the whole paragraph, so a caret inside a cluster deletes only to its end.
let mut end = 0;
for g in text.graphemes(true) {
end += g.chars().count();
if end > ch {
return (pi, end);
}
None => char_move(body, pos, true),
}
char_move(body, pos, true)
}
/// One character left/right across paragraph boundaries.