Skip to content

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

fix(engine): Every command that writes story text reads CR as a paragraph return

moppeeer3ec6f47e26d5
diff --git a/ROADMAP.md b/ROADMAP.md
index 9a0f71e70..ff35770da 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -129,6 +129,8 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-11** · `story.replaceRange`, `story.setText`, notes, footnotes, endnotes, type on a path and table cells read ` ` and `
+` as paragraph returns, as `frame.create` and `text.insert` already did. No readiness percentage change.
- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.
- **2026-10-10** · Version 0.6.0; releases add a Linux riscv64 tar.gz (cross-compiled, CLI
smoke-tested under QEMU).
diff --git a/crates/engine/src/cmd/editorial.rs b/crates/engine/src/cmd/editorial.rs
index 6cee420ed..451c96110 100644
--- a/crates/engine/src/cmd/editorial.rs
+++ b/crates/engine/src/cmd/editorial.rs
@@ -16,7 +16,7 @@ pub fn specs() -> Vec<CommandSpec> {
if ts.cell.is_some() {
return Err(bad("note.new", "notes go in story text"));
}
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
let author = str_param(p, "author").unwrap_or("").to_string();
let at = ts.anchor.max(ts.focus);
s.edit(|d, sel| {
diff --git a/crates/engine/src/cmd/endnotes.rs b/crates/engine/src/cmd/endnotes.rs
index bdf9ca695..664b5c10f 100644
--- a/crates/engine/src/cmd/endnotes.rs
+++ b/crates/engine/src/cmd/endnotes.rs
@@ -4,7 +4,7 @@
use designcraft_doc::{ParaFormat, SpreadRef, StoryId};
use serde_json::{Value, json};
-use super::{CommandSpec, bad, cmd, has_doc, has_text, ok, str_param};
+use super::{CommandSpec, bad, cmd, has_doc, has_text, ok};
use crate::{Result, Session};
pub fn specs() -> Vec<CommandSpec> {
@@ -20,7 +20,7 @@ pub fn specs() -> Vec<CommandSpec> {
),
cmd!("endnote.edit", "Edit Endnote", [], None, "{story, id, text}", has_doc, |s, p| {
let (sid, id) = target(p)?;
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
s.edit(|d, _| {
let style = d.endnote_options.para_style.clone();
let st = d.story_mut(sid).ok_or_else(|| bad("endnote.edit", "no such story"))?;
@@ -103,7 +103,7 @@ fn insert(s: &mut Session, p: &Value) -> Result<Value> {
if st.doc.endnote_story == Some(ts.story) {
return Err(bad(ID, "the endnote frame lists the endnotes"));
}
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
let at = ts.anchor.max(ts.focus);
s.edit(|d, sel| {
// The endnote frame: a text frame in the margins of a new last page.
diff --git a/crates/engine/src/cmd/notes.rs b/crates/engine/src/cmd/notes.rs
index 4d7b0f13f..c17dc6cdb 100644
--- a/crates/engine/src/cmd/notes.rs
+++ b/crates/engine/src/cmd/notes.rs
@@ -3,7 +3,7 @@
use designcraft_doc::{CellAddr, FootnoteOptions, ParaFormat, StoryId, TextSel};
use serde_json::{Value, json};
-use super::{CommandSpec, bad, cmd, has_doc, str_param};
+use super::{CommandSpec, bad, cmd, has_doc};
use crate::{Result, Session};
pub fn specs() -> Vec<CommandSpec> {
@@ -58,7 +58,7 @@ fn in_note(s: &Session) -> std::result::Result<(), String> {
}
fn insert(s: &mut Session, p: &Value) -> Result<Value> {
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
s.edit(|d, sel| {
let t = sel.text.ok_or_else(|| bad("footnote.insert", "no insertion point"))?;
let para = ParaFormat { style: d.footnote_options.para_style.clone(), ..Default::default() };
@@ -130,7 +130,7 @@ fn list(s: &mut Session, p: &Value) -> Result<Value> {
fn set_text(s: &mut Session, p: &Value) -> Result<Value> {
let sid = story_id(p, "footnote.setText")?;
let id = note_id(p, "footnote.setText")?;
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
s.edit(|d, _| {
let st = d.story_mut(sid).ok_or(designcraft_doc::DocError::NoStory(sid))?;
let n = st.note_mut(id).ok_or_else(|| bad("footnote.setText", format!("no footnote {id}")))?;
diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rs
index 17c44c27a..cc9a5fbc7 100644
--- a/crates/engine/src/cmd/object.rs
+++ b/crates/engine/src/cmd/object.rs
@@ -2566,6 +2566,11 @@ mod line_end_tests {
s.execute("text.insert", &json!({"text": "\rFour", "raw": true})).unwrap();
assert_eq!(story(&s).text, "One\nTwo\nThree\nFour");
assert_eq!(story(&s).paras.len(), 4);
+ // Editing a range or the whole story (scripts written for InDesign end paragraphs with \r).
+ s.execute("story.replaceRange", &json!({"story": sid.0, "start": 0, "end": 3, "text": "Zero\rOne"})).unwrap();
+ assert_eq!((story(&s).text.as_str(), story(&s).paras.len()), ("Zero\nOne\nTwo\nThree\nFour", 5));
+ s.execute("story.setText", &json!({"story": sid.0, "text": "A\r\nB\rC"})).unwrap();
+ assert_eq!((story(&s).text.as_str(), story(&s).paras.len()), ("A\nB\nC", 3));
}
}
diff --git a/crates/engine/src/cmd/path_type.rs b/crates/engine/src/cmd/path_type.rs
index 77bbf87ab..6d0da227d 100644
--- a/crates/engine/src/cmd/path_type.rs
+++ b/crates/engine/src/cmd/path_type.rs
@@ -36,7 +36,7 @@ fn align_param(p: &Value) -> Result<Option<PathAlign>> {
fn on_path(s: &mut Session, p: &Value) -> Result<Value> {
let id = super::id_param(p, "id").ok_or_else(|| bad("type.onPath", "missing id"))?;
- let text = super::str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
let mut pt = PathType {
start: p.get("start").and_then(Value::as_f64).unwrap_or(0.0).max(0.0),
flip: p.get("flip").and_then(Value::as_bool).unwrap_or(false),
diff --git a/crates/engine/src/cmd/table.rs b/crates/engine/src/cmd/table.rs
index 9929c1c71..732f5e0bf 100644
--- a/crates/engine/src/cmd/table.rs
+++ b/crates/engine/src/cmd/table.rs
@@ -645,7 +645,7 @@ fn set_cell(s: &mut Session, p: &Value) -> Result<Value> {
Some(o) => return Err(bad("table.setCell", format!("unknown vj `{o}`"))),
None => None,
};
- let text = str_param(p, "text").map(str::to_string);
+ let text = str_param(p, "text").map(|_| super::text_param(p, "text"));
let stroke = p.get("stroke").cloned();
edit_table(s, &g, "table.setCell", |t| {
let owners = t.owners();
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index 4950d82b9..208602cc1 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -76,7 +76,7 @@ pub fn specs() -> Vec<CommandSpec> {
),
cmd!("story.setText", "Set Story Text", [], None, "{story, text} — replace a story's whole text", has_doc, |s, p| {
let sid = StoryId(p.get("story").and_then(Value::as_u64).ok_or_else(|| bad("story.setText", "missing story"))?);
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
s.edit(|d, sel| {
d.set_story_text(sid, &text)?;
if let Some(t) = sel.text.as_mut().filter(|t| t.story == sid) {
@@ -97,7 +97,7 @@ pub fn specs() -> Vec<CommandSpec> {
let sid = StoryId(p.get("story").and_then(Value::as_u64).ok_or_else(|| bad("story.replaceRange", "missing story"))?);
let a = p.get("start").and_then(Value::as_u64).unwrap_or(0) as usize;
let b = p.get("end").and_then(Value::as_u64).map(|v| v as usize).unwrap_or(a);
- let text = str_param(p, "text").unwrap_or("").to_string();
+ let text = super::text_param(p, "text");
s.edit(|d, sel| {
let st = d.story_mut(sid).ok_or(designcraft_doc::DocError::NoStory(sid))?;
let (a, b) = (a.min(st.len()), b.min(st.len()).max(a.min(st.len())));