Skip to content

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

Merge PR #859 (with main's 255-click limit kept inside its event budget)

Brandon Thomasd07cbbe94c27
diff --cc ROADMAP.md
index 278bd6a89,6c6c09c76..9f8168e50
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -1,9 -1,8 +1,10 @@@
# DesignCraft roadmap
-**Stage: pre-alpha** · next: alpha, ~0% and ~15–25 h away; beta ~28 points and ~420–750 h beyond that (the core-workflow gate, not the percentage: ready for real work is already ~47%)
+**Stage: pre-alpha** · next: alpha, ~5–7 h away; beta ~28 points and ~420–750 h beyond that (the core-workflow gate, not the percentage: ready for real work is already ~47%)
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (text threads by hand; the alpha gate waits on Primary Text Frame page fixes) · **Target:** Adobe InDesign 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (parent canvas refresh) · **Target:** Adobe InDesign 2026
+ > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (bounded control click/drag input) · **Target:** Adobe InDesign 2026
DesignCraft aims at full Adobe InDesign parity, and to be better: faster, open (documented JSON
format + IDML), scriptable by agents (MCP), and available on the web.
@@@ -127,30 -127,9 +128,31 @@@ list) · [roadmap.md](docs/roadmap.md)
## Progress log
+- **2026-10-13** · Switching between document and parent pages refreshes the canvas immediately, preventing black parent pages and stale document objects when the zoom stays the same. Ordinary edits retain partial repainting. No readiness percentage change.
+
Newest first.
+- **2026-10-13** · Object › Fitting has InDesign's shortcuts: Fill Frame Proportionally ⌘⌥⇧C, Fit Content Proportionally ⌘⌥⇧E, Fit Frame to Content ⌘⌥C, Fit Content to Frame ⌘⌥E, Center Content ⌘⇧E. No readiness percentage change.
+- **2026-10-13** · Gradients between process colours blend as inks, as InDesign shows them: magenta to cyan passes through C 50 M 50 (a light lilac) on screen instead of the darker RGB mix, and a midpoint between CMYK or grey stops no longer turns the PDF shading RGB. No readiness percentage change.
+- **2026-10-14** · The Swatches panel has InDesign's header: a Fill/Stroke proxy, Formatting Affects Container/Text and the Tint of the colour in front (a tint alone keeps each object's own swatch). Clicking a swatch applies it to the fill or stroke in front (of the text, when formatting affects text), and the bottom row has New Color Group, New Swatch and Delete Swatch. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · On an object-based page the Page tool shows a selected object's liquid pins and resize locks as InDesign does: a click pins a side to the page edge or locks the width or height, with InDesign's tooltips. No readiness percentage change.
+- **2026-10-14** · The Liquid Layout panel follows InDesign's: Liquid Page Rule with the page number, Content › Auto-Fit, and Object Constraints › Resize with Page and Pin for the selected object on an object-based page; Create Alternate Layout moved to the Layout menu. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · The Page tool works as InDesign's: a click selects a page and shows its handles and liquid page rule; dragging a handle previews the rule and springs back, Alt-drag resizes the page from the opposite edge, Shift keeps proportions, with a W/H readout. No readiness percentage change.
+- **2026-10-14** · With the Page tool, a guide dragged from a ruler is a liquid guide (dashed), as in InDesign; guide-based pages stretch the objects it crosses. No readiness percentage change.
+- **2026-10-14** · The Pages panel menu follows InDesign's order: Insert Pages…, Move Pages…, Duplicate Spread (and at End of Document), Delete Page/Spread, New Parent…, Apply Parent to Pages, Override All Parent Page Items, Parent Pages, Create Alternate Layout…, Numbering & Section Options…, Allow Selected Spread to Shuffle. No readiness percentage change.
+- **2026-10-14** · Pages panel: Alt-drag copies a page, a page dropped on Create new page is duplicated at the end, Edit page size offers the presets and Custom Page Size…; duplicated pages keep their own size, rule and guides; thumbnails of pages of their own size stay in their rows. No readiness percentage change.
+- **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load
+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or
+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the
+ frame just added; click the linked frame or double-click a port to break the thread.
+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers
+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No
+ readiness percentage change.
+- **2026-10-13** · Layout ▸ Table of Contents opens a real dialog: title and title style, Include Paragraph Styles and Other Styles lists with Add and Remove, and per style its entry style, page number position (after, before, none), separator and level. Replace Existing regenerates the current table of contents in place; otherwise OK makes a new frame on the page in view. IDML export writes the definition as a TOC style that import reads back, so Update works after a round trip. No readiness percentage change.
+ - **2026-10-13** · Control-channel clicks and drags validate positive counts and the complete pending-event budget before queuing input (#732). Oversized requests leave pending gestures intact, preventing unbounded click-count allocation. No readiness percentage change.
- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.
- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.
- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.
diff --cc crates/ui-egui/src/control.rs
index b85ac04ac,232f2ca21..8ee456520
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@@ -100,16 -100,28 +100,40 @@@ fn key_from(name: &str) -> Option<egui:
})
}
+ // Retain room for the existing maximum drag (10,000 moves plus move/down/up), but
+ // bound the whole gesture and already queued input before generating any events.
+ const MAX_PENDING_POINTER_EVENTS: usize = 10_003;
+
+ fn pointer_counts(p: &Value, drag: bool, pending: usize) -> Result<(u64, u64), String> {
+ let positive = |name: &str, default: u64| match p.get(name) {
+ None => Ok(default),
+ Some(v) => v.as_u64().filter(|n| *n > 0).ok_or_else(|| format!("`{name}` must be a positive integer")),
+ };
+ let count = positive("count", 1)?;
++ if count > 255 {
++ return Err("`count` must be an integer from 1 through 255".into());
++ }
+ let steps = if drag { positive("steps", 8)? } else { 0 };
+ // One initial move, two button events per click, and each drag step. Check the
+ // arithmetic too: hostile counts must never overflow into a small budget.
+ let events = count.checked_mul(2).and_then(|n| n.checked_add(steps)).and_then(|n| n.checked_add(1));
+ let available = MAX_PENDING_POINTER_EVENTS.saturating_sub(pending) as u64;
+ if events.is_none_or(|n| n > available) {
+ return Err(format!("pointer input would exceed the {MAX_PENDING_POINTER_EVENTS} pending-event limit"));
+ }
+ Ok((count, steps))
+ }
+
+/// Handle one control request. Commands it runs leave the user's system clipboard alone.
pub fn handle(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest) -> Outcome {
+ app.install_clipboard_guard(ctx);
+ let was = std::mem::replace(&mut app.in_control, true);
+ let out = handle_request(app, ctx, req);
+ app.in_control = was;
+ out
+}
+
+fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest) -> Outcome {
let p = &req.params;
let s = |k: &str| p.get(k).and_then(Value::as_str);
match req.method.as_str() {
@@@ -196,14 -201,11 +220,11 @@@
ok(Value::Null)
}
"ui.click" | "ui.drag" => {
- let count = match p.get("count") {
- None => 1,
- Some(v) => match v.as_u64().filter(|n| (1..=255).contains(n)) {
- Some(n) => n,
- None => return err("`count` must be an integer from 1 through 255"),
- },
- };
// Screen-space (egui points) pointer input through egui itself: reaches every widget.
- let (count, steps) = match pointer_counts(p, req.method == "ui.drag", app.synthetic.len()) {
++ let (count, steps) = match pointer_counts(p, req.method == "ui.drag", app.control_synthetic.len().saturating_add(app.synthetic.len())) {
+ Ok(counts) => counts,
+ Err(e) => return err(e),
+ };
let f = |k: &str| p.get(k).and_then(Value::as_f64).unwrap_or(0.0) as f32;
let button = match s("button") {
Some("right") | Some("secondary") => egui::PointerButton::Secondary,
@@@ -220,20 -222,18 +241,18 @@@
};
let a = egui::pos2(f("x"), f("y"));
let end = if req.method == "ui.drag" { egui::pos2(f("toX"), f("toY")) } else { a };
- app.synthetic.push(egui::Event::PointerMoved(a));
- app.synthetic.push(egui::Event::PointerButton { pos: a, button, pressed: true, modifiers });
+ app.control_synthetic.push(egui::Event::PointerMoved(a));
+ app.control_synthetic.push(egui::Event::PointerButton { pos: a, button, pressed: true, modifiers });
if req.method == "ui.drag" {
- // From the caller: a huge count would queue events until memory runs out.
- let steps = p.get("steps").and_then(Value::as_u64).unwrap_or(8).clamp(1, 10_000);
for i in 1..=steps {
let t = i as f32 / steps as f32;
- app.synthetic.push(egui::Event::PointerMoved(a + (end - a) * t));
+ app.control_synthetic.push(egui::Event::PointerMoved(a + (end - a) * t));
}
}
- app.synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: false, modifiers });
+ app.control_synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: false, modifiers });
for _ in 1..count {
- app.synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: true, modifiers });
- app.synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: false, modifiers });
+ app.control_synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: true, modifiers });
+ app.control_synthetic.push(egui::Event::PointerButton { pos: end, button, pressed: false, modifiers });
}
ctx.request_repaint();
ok(Value::Null)
@@@ -448,6 -442,127 +467,127 @@@ mod automation_contract_tests
output.textures_delta.clear();
}
#[test]
+ fn oversized_pointer_requests_leave_pending_events_unchanged() {
+ let mut app = app();
+ let ctx = egui::Context::default();
+ let pending = vec![egui::Event::PointerMoved(egui::pos2(12.0, 34.0))];
+ for (method, params) in [
+ ("ui.click", json!({"count": 5002})),
+ ("ui.drag", json!({"steps": 10000, "count": 2})),
+ ("ui.drag", json!({"steps": 10001})),
+ ("ui.click", json!({"count": u64::MAX})),
+ ("ui.drag", json!({"steps": u64::MAX})),
+ ("ui.drag", json!({"count": u64::MAX, "steps": u64::MAX})),
+ ] {
- app.synthetic = pending.clone();
++ app.control_synthetic = pending.clone();
+ let reply = call(&mut app, &ctx, method, params);
+ assert_eq!(reply["ok"], false, "{method}: {reply}");
- assert_eq!(app.synthetic, pending, "a rejected gesture must not leave a press queued");
++ assert_eq!(app.control_synthetic, pending, "a rejected gesture must not leave a press queued");
+ }
+ }
+ #[test]
+ fn pointer_counts_require_positive_json_integers() {
+ let mut app = app();
+ let ctx = egui::Context::default();
+ let pending = vec![egui::Event::PointerMoved(egui::pos2(12.0, 34.0))];
- app.synthetic = pending.clone();
++ app.control_synthetic = pending.clone();
+ for value in [json!(0), json!(-1), json!(1.5), Value::Null, json!("2"), json!(true), json!(18446744073709551616_f64)] {
+ for (method, field) in [("ui.click", "count"), ("ui.drag", "count"), ("ui.drag", "steps")] {
+ let mut params = json!({});
+ params[field] = value.clone();
+ let reply = call(&mut app, &ctx, method, params);
+ assert_eq!(reply["ok"], false, "{method}, {field}={value}: {reply}");
+ assert!(reply["error"].as_str().unwrap().contains(field));
- assert_eq!(app.synthetic, pending);
++ assert_eq!(app.control_synthetic, pending);
+ }
+ }
+ }
+ #[test]
+ fn pointer_gestures_accept_the_exact_event_budget() {
+ let mut app = app();
+ let ctx = egui::Context::default();
+ for (method, params) in
- [("ui.click", json!({"count": 5001})), ("ui.drag", json!({"steps": 10000})), ("ui.drag", json!({"steps": 9998, "count": 2}))]
++ [("ui.drag", json!({"steps": 9492, "count": 255})), ("ui.drag", json!({"steps": 10000})), ("ui.drag", json!({"steps": 9998, "count": 2}))]
+ {
- app.synthetic.clear();
++ app.control_synthetic.clear();
+ assert_eq!(call(&mut app, &ctx, method, params)["ok"], true, "{method}");
- assert_eq!(app.synthetic.len(), 10003);
- assert!(matches!(app.synthetic.last(), Some(egui::Event::PointerButton { pressed: false, .. })));
- let queued = app.synthetic.clone();
++ assert_eq!(app.control_synthetic.len(), 10003);
++ assert!(matches!(app.control_synthetic.last(), Some(egui::Event::PointerButton { pressed: false, .. })));
++ let queued = app.control_synthetic.clone();
+ assert_eq!(call(&mut app, &ctx, "ui.click", json!({}))["ok"], false);
- assert_eq!(app.synthetic, queued, "a full queue retains its release events");
++ assert_eq!(app.control_synthetic, queued, "a full queue retains its release events");
+ }
+ }
+ #[test]
+ fn pointer_budget_counts_pending_input_and_recovers_when_it_drains() {
+ let mut app = app();
+ let ctx = egui::Context::default();
- assert_eq!(call(&mut app, &ctx, "ui.click", json!({"count": 5000}))["ok"], true);
- assert_eq!(app.synthetic.len(), 10001);
- let queued = app.synthetic.clone();
++ assert_eq!(call(&mut app, &ctx, "ui.drag", json!({"steps": 9998}))["ok"], true);
++ assert_eq!(app.control_synthetic.len(), 10001);
++ let queued = app.control_synthetic.clone();
+ assert_eq!(call(&mut app, &ctx, "ui.click", json!({}))["ok"], false);
- assert_eq!(app.synthetic, queued);
++ assert_eq!(app.control_synthetic, queued);
+ // The ordinary input hook consumes one pointer event per frame, freeing
+ // enough room for a complete click without dropping earlier input.
+ app.raw_input_hook(&mut egui::RawInput::default());
- assert_eq!(app.synthetic.len(), 10000);
++ assert_eq!(app.control_synthetic.len(), 10000);
+ assert_eq!(call(&mut app, &ctx, "ui.click", json!({}))["ok"], true);
- assert_eq!(app.synthetic.len(), 10003);
++ assert_eq!(app.control_synthetic.len(), 10003);
+
- app.synthetic.clear();
++ app.control_synthetic.clear();
+ assert_eq!(call(&mut app, &ctx, "ui.move", json!({"x": 12, "y": 34}))["ok"], true);
- let queued = app.synthetic.clone();
++ let queued = app.control_synthetic.clone();
+ assert_eq!(call(&mut app, &ctx, "ui.drag", json!({"steps": 10000}))["ok"], false);
- assert_eq!(app.synthetic, queued);
++ assert_eq!(app.control_synthetic, queued);
+ assert_eq!(call(&mut app, &ctx, "ui.drag", json!({"steps": 9999}))["ok"], true);
- assert_eq!(app.synthetic.len(), 10003);
++ assert_eq!(app.control_synthetic.len(), 10003);
+ }
+ #[test]
+ fn ordinary_pointer_gestures_keep_their_defaults_and_event_order() {
+ let mut app = app();
+ let ctx = egui::Context::default();
+ let a = egui::pos2(10.0, 20.0);
+ let end = egui::pos2(30.0, 40.0);
+ assert_eq!(call(&mut app, &ctx, "ui.click", json!({"x": 10, "y": 20}))["ok"], true);
+ assert_eq!(
- app.synthetic,
++ app.control_synthetic,
+ vec![
+ egui::Event::PointerMoved(a),
+ egui::Event::PointerButton { pos: a, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE },
+ egui::Event::PointerButton { pos: a, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE },
+ ]
+ );
- app.synthetic.clear();
++ app.control_synthetic.clear();
+ assert_eq!(call(&mut app, &ctx, "ui.drag", json!({"x": 10, "y": 20, "toX": 30, "toY": 40}))["ok"], true);
- assert_eq!(app.synthetic.len(), 11, "default drag has eight steps");
- assert_eq!(app.synthetic.get(9), Some(&egui::Event::PointerMoved(end)));
++ assert_eq!(app.control_synthetic.len(), 11, "default drag has eight steps");
++ assert_eq!(app.control_synthetic.get(9), Some(&egui::Event::PointerMoved(end)));
+
- app.synthetic.clear();
++ app.control_synthetic.clear();
+ assert_eq!(
+ call(
+ &mut app,
+ &ctx,
+ "ui.drag",
+ json!({"x": 10, "y": 20, "toX": 30, "toY": 40, "steps": 2, "count": 2, "button": "right", "shift": true})
+ )["ok"],
+ true
+ );
+ let modifiers = egui::Modifiers { shift: true, ..Default::default() };
+ let button = egui::PointerButton::Secondary;
+ assert_eq!(
- app.synthetic,
++ app.control_synthetic,
+ vec![
+ egui::Event::PointerMoved(a),
+ egui::Event::PointerButton { pos: a, button, pressed: true, modifiers },
+ egui::Event::PointerMoved(egui::pos2(20.0, 30.0)),
+ egui::Event::PointerMoved(end),
+ egui::Event::PointerButton { pos: end, button, pressed: false, modifiers },
+ egui::Event::PointerButton { pos: end, button, pressed: true, modifiers },
+ egui::Event::PointerButton { pos: end, button, pressed: false, modifiers },
+ ]
+ );
+ }
+ #[test]
fn control_typing_uses_explicit_caret_but_retains_widget_events() {
let mut app = app();
let ctx = egui::Context::default();
diff --cc docs/control-protocol.md
index 439987252,6615eb103..25136a807
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@@ -37,9 -37,9 +37,9 @@@ so only enable it while you use it. Tra
| `ui.inspect` | — | Tool, UI state, view (zoom/origin), canvas rect, perf |
| `ui.menu.list` / `ui.tool.list` | — | Menu tree / Tools panel groups |
| `ui.tool.select` | `{tool}` | Select a tool (`selection`, `type`, `rectangleFrame`, …) |
-| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick, x, y, space?: "screen"\|"canvas"}], mods?}` | Drive the active tool through the same code path as the mouse |
+| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick, x, y, space?: "screen"\|"canvas", clicks?}], mods?}` | Drive the active tool through the same code path as the mouse; `clicks` on a `down` is the press count (3 = triple click); returns the selection, the tool and its cursor at the last event (e.g. `LoadedText`, `ThreadLink`, `Unthread`) |
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | Synthetic keyboard input (typing into a text frame) |
- | `ui.move` / `ui.click` / `ui.drag` | screen points, `button?: left\|right\|middle` | Real egui pointer input — reaches every widget, menu and panel |
+ | `ui.move` / `ui.click` / `ui.drag` | screen points, `button?: left\|right\|middle`, `count?: positive integer` (click/drag, default 1), `steps?: positive integer` (drag, default 8) | Real egui pointer input — reaches every widget, menu and panel |
| `ui.set` | `{brightness?, panel?, rulers?, guides?, frameEdges?, baselineGrid?, textThreads?, screenMode?, zoom?, page?, fit?}` | UI state |
| `ui.dialog.open` | `{id, fields?}` | Open a dialog by id (e.g. `paragraphStyleOptions` or `characterStyleOptions` with `{name, section}`, or `{new: true}` for a new style) |
| `ui.dialog.set` / `ui.dialog.confirm` / `ui.dialog.cancel` | `{field, value}` | Fill and confirm the open dialog |
@@@ -57,6 -57,17 +57,17 @@@ Headless window screenshots (locked scr
The MCP server (`designcraft-cli mcp`) wraps the same methods for Claude and other agents.
+ ### Click and drag limits
+
+ `ui.click` and `ui.drag` validate the whole gesture before queuing any input. They permit at
+ most 10,003 pending synthetic events, including input already waiting for native frames. A
+ click uses `1 + 2 * count` events; a drag uses `1 + steps + 2 * count`. The count includes the
-initial click or drag; further clicks occur at its endpoint. An empty queue therefore accepts
-up to 5,001 clicks, or a single drag with up to 10,000 steps. `count` and `steps` must be positive
++initial click or drag; further clicks occur at its endpoint. `count` is at most 255; an empty
++queue accepts a single drag with up to 10,000 steps. `count` and `steps` must be positive
+ JSON integers when supplied; invalid or over-budget requests return `ok: false` and leave pending
+ input unchanged. Oversized gestures are rejected rather than truncated. Wait for queued input
+ to finish before retrying a request that would exceed the pending-event limit.
+
## Shared panel docking
Panel arrangements support tab grouping and reordering, horizontal and vertical splits,
diff --cc docs/gaps.md
index 41a0af1f3,a578036d6..4ba05bc4e
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@@ -29,9 -35,11 +29,11 @@@ Kind: **F** feature · **U** UI/UX · *
### 1. Basic editing fails for many users (U, S)
- **Missing:** object copy/paste on Windows and Linux (#351, #348, #312, #185, #164, #201, text RTF
paste #212); Paste in Place onto the selected page (#348); right-click context menus that don't
- open (#238, #187, #160, #312); threading (gap 0); double-click word selection in fields
+ open (#238, #187, #160, #312); double-click word selection in fields
(#189); character formatting set at a caret is discarded (#289).
- **Evidence:** 16 issues from 2026-10-05 to 2026-10-10, mostly against the 0.4/0.5 release builds.
+ - **Safety:** control-channel clicks and drags reject invalid or over-budget counts before
+ queuing input (#732), including combined drag steps, repeated clicks and already pending events.
- **Impact:** a layout artist can't finish the simplest job. This dominates the
ready-for-real-work number.
- **Estimate:** 30–50 h (reproduce per platform through the control channel, regression tests).