Treat CRLF as a single paragraph break in text.set

Found while testing crates/engine/src/cmd/text.rs:1219 (set), via crates/model/src/text.rs:605 (TextBody::from_text)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-21 00:13:45 +00:00
co-authored by Claude Haiku 5.5
parent a31b990d32
commit 309d9f5b2c
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -94,6 +94,19 @@ fn text_editing_flow() {
assert_eq!(s.doc().unwrap().selection.shapes.len(), 1);
}
/// `text.set` treats CRLF as one paragraph break and keeps no `\r` in the text.
#[test]
fn text_set_crlf_makes_clean_paragraphs() {
let mut s = session();
let r = s.execute("insert.textBox", &json!({"text": "x"})).unwrap();
let id = r["id"].as_u64().unwrap();
s.execute("text.set", &json!({"id": id, "text": "one\r\ntwo"})).unwrap();
let t = s.execute("text.get", &json!({"id": id})).unwrap();
assert_eq!(t["paragraphs"][0]["text"], "one");
assert_eq!(t["paragraphs"][1]["text"], "two");
assert_eq!(t["text"], "one\ntwo");
}
/// Cut with only a caret copies nothing, so it must not delete the character after the caret.
#[test]
fn cut_with_only_a_caret_changes_nothing() {
+1
View File
@@ -603,6 +603,7 @@ pub struct TextBody {
impl TextBody {
pub fn from_text(text: &str) -> Self {
let text = text.replace("\r\n", "\n");
TextBody { paragraphs: text.split('\n').map(Paragraph::new).collect(), ..Default::default() }
}
/// Plain text with `\n` between paragraphs.