From 309d9f5b2c2d1e4fddc3a96f8db63b4ce0f14a1e Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Wed, 21 Oct 2026 00:13:45 +0000 Subject: [PATCH 1/2] 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 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/tests.rs | 13 +++++++++++++ crates/model/src/text.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index dd64b08cd..7b21ad261 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -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() { diff --git a/crates/model/src/text.rs b/crates/model/src/text.rs index b317d3d98..4b0185941 100644 --- a/crates/model/src/text.rs +++ b/crates/model/src/text.rs @@ -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. From b6bd10e0a81a47e5481c7406a341d9e19e087fc4 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 23 Oct 2026 17:13:31 -0400 Subject: [PATCH 2/2] text.set: a lone CR is a paragraph break too Matches edit::insert, which already maps a bare \r to \n. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 6 +++++- crates/model/src/text.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 7b21ad261..d0cae0add 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -94,7 +94,7 @@ 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. +/// `text.set` treats CRLF (or a lone CR) as one paragraph break and keeps no `\r` in the text. #[test] fn text_set_crlf_makes_clean_paragraphs() { let mut s = session(); @@ -105,6 +105,10 @@ fn text_set_crlf_makes_clean_paragraphs() { assert_eq!(t["paragraphs"][0]["text"], "one"); assert_eq!(t["paragraphs"][1]["text"], "two"); assert_eq!(t["text"], "one\ntwo"); + // A lone CR (old Mac line ends) is a paragraph break too, as `edit::insert` treats it. + s.execute("text.set", &json!({"id": id, "text": "a\rb"})).unwrap(); + let t = s.execute("text.get", &json!({"id": id})).unwrap(); + assert_eq!(t["text"], "a\nb"); } /// Cut with only a caret copies nothing, so it must not delete the character after the caret. diff --git a/crates/model/src/text.rs b/crates/model/src/text.rs index 4b0185941..4129be4b9 100644 --- a/crates/model/src/text.rs +++ b/crates/model/src/text.rs @@ -603,7 +603,7 @@ pub struct TextBody { impl TextBody { pub fn from_text(text: &str) -> Self { - let text = text.replace("\r\n", "\n"); + let text = text.replace("\r\n", "\n").replace('\r', "\n"); TextBody { paragraphs: text.split('\n').map(Paragraph::new).collect(), ..Default::default() } } /// Plain text with `\n` between paragraphs.