Skip to content

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

T: drag and drop text editing (move, Alt copies)

Brandon Thomasfaa2897ace31
diff --git a/ROADMAP.md b/ROADMAP.md
index f4ea0843f..cfd3efc63 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -30,6 +30,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Edit › Paste Into (copied objects become a frame's content, clipped by it; rendered, PDF and IDML both ways — verified in InDesign 2026); Polygon Settings (sides, star inset; double-click the Polygon tool).
- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.
- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).
+- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).
- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.
- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.
- View › Overprint Preview (⌥⇧⌘Y): overprinting fills, strokes and 100% [Black] text mix with what's beneath on screen.
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index 7c775d337..ecc8e5ad3 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -11,6 +11,15 @@ use crate::{Result, Session};
pub fn specs() -> Vec<CommandSpec> {
vec![
cmd!(noundo "text.placeCaret", "Place Caret", [], None, "{frame, point: [x,y] (spread coords)} — converts empty frames to text frames", has_doc, |s, p| place(s, p, false)),
+ cmd!(
+ "text.release",
+ "Release",
+ [],
+ None,
+ "{frame, point, moved: bool, copy?: bool} — ends a press in text: a drag that started in the selected text moves (copy: duplicates) it to the point; a click places the caret",
+ has_doc,
+ release
+ ),
cmd!(noundo "text.extendTo", "Extend Text Selection", [], None, "{frame, point}", has_doc, |s, p| place(s, p, true)),
cmd!(noundo "text.selectWord", "Select Word", [], None, "{frame, point}", has_doc, |s, p| {
place(s, p, false)?;
@@ -203,6 +212,15 @@ fn place(s: &mut Session, p: &Value, extend: bool) -> Result<Value> {
s.execute("object.content", &json!({"ids": [frame.0], "type": "text"}))?;
}
let (sid, b, cell) = hit_byte(s, frame, pt).ok_or_else(|| bad("text.placeCaret", "not a text frame"))?;
+ // Drag and drop: a press inside the selected text keeps it (to be dragged).
+ if !extend {
+ s.text_drag = s.doc()?.selection.text.is_some_and(|t| t.story == sid && t.cell == cell && !t.range().is_empty() && t.range().contains(&b));
+ if s.text_drag {
+ return Ok(json!({"story": sid.0, "dragging": true}));
+ }
+ } else if s.text_drag {
+ return Ok(json!({"story": sid.0, "dragging": true}));
+ }
let st = s.doc_mut()?;
// Dragging from one cell into another selects cells.
if extend
@@ -226,6 +244,40 @@ fn place(s: &mut Session, p: &Value, extend: bool) -> Result<Value> {
Ok(json!({"story": sid.0, "pos": b, "cell": cell}))
}
+fn release(s: &mut Session, p: &Value) -> Result<Value> {
+ if !std::mem::take(&mut s.text_drag) {
+ return ok();
+ }
+ let frame = id_param(p, "frame").ok_or_else(|| bad("text.release", "missing frame"))?;
+ let pt = point_param(p, "point").unwrap_or(Point::ZERO);
+ if !p.get("moved").and_then(Value::as_bool).unwrap_or(false) {
+ // A click in the selection: the caret goes there.
+ s.doc_mut()?.selection.text = None;
+ return place(s, &json!({"frame": frame.0, "point": [pt.x, pt.y]}), false);
+ }
+ let copy = p.get("copy").and_then(Value::as_bool).unwrap_or(false);
+ let Some(t) = s.doc()?.selection.text else { return ok() };
+ let Some((sid, b, cell)) = hit_byte(s, frame, pt) else { return ok() };
+ let r = t.range();
+ if sid != t.story || cell != t.cell || (r.contains(&b) && !copy) {
+ return ok();
+ }
+ s.edit(|d, sel| {
+ let st = d.text_story_mut(sid, cell).ok_or(designcraft_doc::DocError::NoStory(sid))?;
+ let piece = st.extract(r.clone());
+ let mut at = b;
+ if !copy {
+ st.delete(r.clone());
+ if at > r.start {
+ at -= r.len().min(at - r.start);
+ }
+ }
+ let end = st.insert_story(at, &piece);
+ sel.text = Some(TextSel { story: sid, anchor: at, focus: end, frame: Some(frame), cell });
+ Ok(json!({"moved": piece.text.len(), "at": at}))
+ })
+}
+
fn insert(s: &mut Session, p: &Value) -> Result<Value> {
let text = str_param(p, "text").unwrap_or("").to_string();
// Tab in a table cell moves to the next cell (Shift-Tab: `table.prevCell`).
@@ -846,3 +898,48 @@ mod nested_style_tests {
assert_eq!(fill_at(text.find("2026").unwrap()), "C=0 M=100 Y=0 K=0", "GREP: digits");
}
}
+
+#[cfg(test)]
+mod drag_text_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ #[test]
+ fn drag_selected_text_to_move_or_copy_it() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 200], "content": "text", "text": "Hello brave world"})).unwrap();
+ let (fid, sid) = (r["id"].as_u64().unwrap(), r["story"].as_u64().unwrap());
+ // Spread point of the glyph at byte `b`.
+ let at = |s: &Session, b: usize| {
+ let d = &s.doc().unwrap().doc;
+ let cs = designcraft_compose::compose_story(d, designcraft_doc::StoryId(sid), &Default::default());
+ let l = &cs.frames[0].lines[0];
+ let g = l.glyphs.iter().find(|g| g.byte == b).unwrap();
+ json!([g.x + g.adv * 0.25, l.baseline - 3.0])
+ };
+ let end = |s: &Session| {
+ let d = &s.doc().unwrap().doc;
+ let cs = designcraft_compose::compose_story(d, designcraft_doc::StoryId(sid), &Default::default());
+ let l = &cs.frames[0].lines[0];
+ json!([l.end_x + 2.0, l.baseline - 3.0])
+ };
+ s.execute("text.select", &json!({"story": sid, "anchor": 6, "focus": 12})).unwrap();
+ let r = s.execute("text.placeCaret", &json!({"frame": fid, "point": at(&s, 8)})).unwrap();
+ assert_eq!(r["dragging"], true);
+ s.execute("text.extendTo", &json!({"frame": fid, "point": end(&s)})).unwrap();
+ s.execute("text.release", &json!({"frame": fid, "point": end(&s), "moved": true})).unwrap();
+ let text = |s: &Session| s.doc().unwrap().doc.story(designcraft_doc::StoryId(sid)).unwrap().text.clone();
+ assert_eq!(text(&s), "Hello worldbrave ");
+ // Alt-drag copies (the moved text is still selected).
+ s.execute("text.placeCaret", &json!({"frame": fid, "point": at(&s, 12)})).unwrap();
+ s.execute("text.release", &json!({"frame": fid, "point": at(&s, 0), "moved": true, "copy": true})).unwrap();
+ assert_eq!(text(&s), "brave Hello worldbrave ");
+ // A click inside the selection just places the caret.
+ s.execute("text.placeCaret", &json!({"frame": fid, "point": at(&s, 2)})).unwrap();
+ s.execute("text.release", &json!({"frame": fid, "point": at(&s, 2), "moved": false})).unwrap();
+ let t = s.doc().unwrap().selection.text.unwrap();
+ assert_eq!(t.anchor, t.focus);
+ }
+}
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index f443c83cd..b129ae5e0 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -171,6 +171,8 @@ pub struct Session {
/// Again), with the selection they were applied to and whether the last one came from a
/// tool interaction (its previews replace each other).
pub(crate) transforms: (Vec<(String, Value)>, Vec<designcraft_doc::ItemId>, bool),
+ /// Drag and drop text editing: the press landed in the selected text.
+ pub(crate) text_drag: bool,
}
impl Default for Session {
@@ -194,6 +196,7 @@ impl Session {
ui_requests: vec![],
loaded: None,
transforms: Default::default(),
+ text_drag: false,
untitled: 0,
}
}
diff --git a/crates/tools/src/text.rs b/crates/tools/src/text.rs
index 4de65bc04..a92e14732 100644
--- a/crates/tools/src/text.rs
+++ b/crates/tools/src/text.rs
@@ -66,11 +66,20 @@ impl Tool for TypeTool {
out
}
PointerKind::Up => {
- self.start = None;
- self.selecting = None;
+ let start = self.start.take();
if std::mem::take(&mut self.drawing) {
+ self.selecting = None;
return vec![Action::Commit];
}
+ // Ends a press in text: drops dragged text, or is ignored by the engine.
+ if let Some(fid) = self.selecting.take() {
+ let sp = cx.layout.spread_at(ev.pos).map(|(_, p)| p).unwrap_or(ev.pos);
+ let moved = start.is_some_and(|a| (ev.pos - a).hypot() >= cx.tol(3.0));
+ return vec![Action::Exec(
+ "text.release".into(),
+ json!({"frame": fid, "point": [sp.x, sp.y], "moved": moved, "copy": ev.mods.alt}),
+ )];
+ }
vec![]
}
PointerKind::Move => vec![],
diff --git a/docs/parity.md b/docs/parity.md
index 1f29229ab..d15795104 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -5,12 +5,12 @@ The summary is generated by `cargo xtask parity` from the table at the bottom of
Each row of the InDesign feature catalogue is scored **D** (done), **P** (partial: works but lacks options or UI) or **M** (missing), weighted by priority (**P0** core = 3, **P1** = 2, **P2** = 1). Out-of-scope rows (Adobe cloud services, plug-ins, Typekit, Flash) are excluded.
<!-- SUMMARY -->
-**Weighted breadth parity: 81%** over 275 features.
+**Weighted breadth parity: 82%** over 275 features.
| Priority | Features | Done | Partial | Missing | Parity |
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
-| P1 | 97 | 65 | 26 | 6 | 80% |
+| P1 | 97 | 66 | 26 | 5 | 81% |
| P2 | 76 | 8 | 7 | 61 | 15% |
| Area | Parity |
@@ -23,7 +23,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia
| Fill, stroke, colour | 81% |
| Effects & transparency | 50% |
| Placing & links | 81% |
-| Type & text frames | 85% |
+| Type & text frames | 88% |
| Typography | 85% |
| Styles | 92% |
| Tables | 81% |
@@ -211,7 +211,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Type & text frames | Data merge | P2 | D |
| Type & text frames | Smart quotes | P0 | D |
| Type & text frames | Autocorrect / Dynamic spelling | P2 | P |
-| Type & text frames | Drag & drop text editing | P1 | M |
+| Type & text frames | Drag & drop text editing | P1 | D |
| Type & text frames | Paste text with/without formatting | P0 | D |
| Type & text frames | Math expressions | P2 | M |
| Type & text frames | Right-to-left / World-Ready composer | P2 | M |