Skip to content

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

Eyedropper: with text selected, pick up the clicked text's formatting

moppeeerc9a096826b7c
diff --git a/ROADMAP.md b/ROADMAP.md
index 9f8168e50..56f77c5a7 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -132,6 +132,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-15** · The Eyedropper with text selected picks up the formatting of the text it clicks (character style and overrides, paragraph style and overrides) and applies it to the selection, as InDesign's does; it copied the clicked frame's fill and stroke instead. No readiness percentage change.
- **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.
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index add94aca9..7625e36e1 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -34,6 +34,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_doc,
|s, p| select_at(s, p, str_param(p, "unit").unwrap_or("word"))
),
+ cmd!(
+ "type.pickUpFormat",
+ "Apply Text Attributes (Eyedropper)",
+ [],
+ None,
+ "{frame, point} — the Eyedropper with text selected: the character and paragraph formatting (styles and overrides) of the text under the point go to the selected text",
+ has_text,
+ pick_up_format
+ ),
cmd!(noundo "text.selectSentence", "Select Sentence", [], None, "{frame, point} — the sentence under the point", has_doc, |s, p| {
select_around(s, p, "text.selectSentence", sentence_bounds)
}),
@@ -340,6 +349,38 @@ fn hit_byte_with(
Some((sid, b, None))
}
+/// The Eyedropper with text selected: the formatting of the text under `point` in `frame` goes to
+/// the selection, as InDesign's does (character style and overrides on the selected characters,
+/// paragraph style and overrides on their paragraphs).
+fn pick_up_format(s: &mut Session, p: &Value) -> Result<Value> {
+ const ID: &str = "type.pickUpFormat";
+ let frame = id_param(p, "frame").ok_or_else(|| bad(ID, "missing frame"))?;
+ let pt = point_param(p, "point").ok_or_else(|| bad(ID, "missing point"))?;
+ let (sid, b, cell) = hit_byte_with(s, frame, pt, compose::hit_char).ok_or_else(|| bad(ID, "not a text frame"))?;
+ let st = s.doc()?;
+ let sel = st.selection.text.ok_or_else(|| bad(ID, "select the text to format"))?;
+ let src = st.doc.text_story(sid, cell).ok_or(designcraft_doc::DocError::NoStory(sid))?;
+ let b = floor_char_boundary(&src.text, b);
+ // The character under the pointer (at the end of a line, the one before it).
+ let at = if b >= src.text.len() || src.text[b..].starts_with('\n') { b.saturating_sub(1) } else { b };
+ let at = floor_char_boundary(&src.text, at);
+ let chars = src.char_format_at(at).clone();
+ let para = src.paras.get(src.para_at(at)).cloned().ok_or(designcraft_doc::DocError::NoStory(sid))?;
+ let (a, e) = (sel.anchor.min(sel.focus), sel.anchor.max(sel.focus));
+ s.typing_format = None;
+ s.edit(|d, _| {
+ let story = d.text_story_mut(sel.story, sel.cell).ok_or(designcraft_doc::DocError::NoStory(sel.story))?;
+ if e > a {
+ story.format_chars(a..e, |f| *f = chars.clone());
+ }
+ story.format_paras(a..e, |f| {
+ f.style = para.style.clone();
+ f.para = para.para.clone();
+ });
+ Ok(json!({"style": chars.style, "paragraphStyle": para.style}))
+ })
+}
+
/// Select the word, line, paragraph or story at `point` in `frame` (multiple clicks).
fn select_at(s: &mut Session, p: &Value, unit: &str) -> Result<Value> {
const ID: &str = "text.selectAt";
@@ -2559,3 +2600,42 @@ mod sentence_selection_tests {
assert_eq!(para_bounds(s, s.len()), (s.len(), s.len()));
}
}
+
+#[cfg(test)]
+mod pick_up_format_tests {
+ use designcraft_doc::ItemId;
+ use serde_json::json;
+
+ use crate::Session;
+
+ /// Typefool's video (12:04): select body text, Eyedropper, click the third header: the body
+ /// text takes the header's font, size and paragraph settings. DesignCraft copied the frame's
+ /// fill and stroke instead.
+ #[test]
+ fn the_eyedropper_copies_text_formatting_to_selected_text() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let head = s.execute("frame.create", &json!({"rect": [36, 36, 400, 100], "content": "text", "text": "Innovative Design"})).unwrap();
+ s.execute("text.select", &json!({"story": head["story"], "anchor": 0, "focus": 17})).unwrap();
+ s.execute("type.char", &json!({"attrs": {"fontStyle": "Bold", "size": 18, "tracking": 20}})).unwrap();
+ s.execute("type.para", &json!({"attrs": {"align": "center", "spaceAfter": 6}})).unwrap();
+ let body = s.execute("frame.create", &json!({"rect": [36, 200, 400, 300], "content": "text", "text": "Body copy here.\nSecond."})).unwrap();
+ s.execute("text.select", &json!({"story": body["story"], "anchor": 0, "focus": 4})).unwrap();
+ // Click the header's middle (the frame's text starts at its top left).
+ let r = s.execute("type.pickUpFormat", &json!({"frame": head["id"], "point": [100, 50]})).unwrap();
+ assert!(r.is_object(), "{r}");
+ s.execute("text.select", &json!({"story": body["story"], "anchor": 0, "focus": 4})).unwrap();
+ let a = s.execute("type.selectionAttrs", &json!({})).unwrap();
+ assert_eq!((&a["chars"]["fontStyle"], &a["chars"]["size"], &a["chars"]["tracking"]), (&json!("Bold"), &json!(18.0), &json!(20.0)), "{a}");
+ assert_eq!((&a["para"]["align"], &a["para"]["spaceAfter"]), (&json!("center"), &json!(6.0)));
+ // Only the selected characters change; the second paragraph keeps its own.
+ s.execute("text.select", &json!({"story": body["story"], "anchor": 6, "focus": 10})).unwrap();
+ assert_eq!(s.execute("type.selectionAttrs", &json!({})).unwrap()["chars"]["size"], json!(12.0));
+ s.execute("text.select", &json!({"story": body["story"], "anchor": 17, "focus": 20})).unwrap();
+ assert_eq!(s.execute("type.selectionAttrs", &json!({})).unwrap()["para"]["align"], json!("left"));
+ // Not a text frame, or nothing selected: refused.
+ let rect = s.execute("frame.create", &json!({"rect": [500, 500, 520, 520]})).unwrap()["id"].as_u64().unwrap();
+ assert!(s.execute("type.pickUpFormat", &json!({"frame": rect, "point": [510, 510]})).is_err());
+ let _ = ItemId(rect);
+ }
+}
diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rs
index 6f8493dc4..9390dcbbb 100644
--- a/crates/tools/src/tests.rs
+++ b/crates/tools/src/tests.rs
@@ -1167,3 +1167,20 @@ fn eyedropper_samples_a_placed_image_and_matches_other_objects() {
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0 + off.x, 130.0 + off.y));
assert_eq!(a, vec![Action::Exec("object.matchAttributes".into(), serde_json::json!({"from": photo.0}))]);
}
+
+/// With text selected, the Eyedropper on a text frame picks up its text formatting instead of
+/// copying the frame's fill and stroke onto the selection (InDesign's Eyedropper).
+#[test]
+fn eyedropper_with_text_selected_picks_up_text_formatting() {
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ let (head, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 300.0, 140.0), lid, "Header", ParaFormat::default()).unwrap();
+ let (_, body) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 200.0, 300.0, 300.0), lid, "Body", ParaFormat::default()).unwrap();
+ let s = Selection::text(designcraft_doc::TextSel { story: body, anchor: 0, focus: 4, frame: None, cell: None });
+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
+ let off = l.xf(SpreadRef::Doc(0)).translation();
+ let cx = ctx(&d, &s, &c, &l);
+ let mut t = create("eyedropper");
+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 150.0 + off.x, 120.0 + off.y));
+ assert_eq!(a, vec![Action::Exec("type.pickUpFormat".into(), serde_json::json!({"frame": head.0, "point": [150.0, 120.0]}))]);
+}
diff --git a/crates/tools/src/xform.rs b/crates/tools/src/xform.rs
index e0bcd24f3..f67c84386 100644
--- a/crates/tools/src/xform.rs
+++ b/crates/tools/src/xform.rs
@@ -301,10 +301,15 @@ impl Tool for EyedropperTool {
if selected && let Some((sr, at)) = image_under(cx, ev.pos) {
return vec![Action::Exec("color.sample".into(), json!({"at": [at.x, at.y], "spread": sr}))];
}
- let Some((_, id)) = cx.hit(ev.pos) else { return vec![] };
+ let Some((sr, id)) = cx.hit(ev.pos) else { return vec![] };
if !selected {
return vec![Action::Exec("selection.set".into(), json!({"ids": [id.0]}))];
}
+ // With text selected, clicking text picks up its formatting (InDesign's Eyedropper).
+ if cx.selection.text.is_some() && cx.doc.item(id).is_some_and(|it| it.is_text_frame()) {
+ let p = cx.layout.to_spread(sr, ev.pos);
+ return vec![Action::Exec("type.pickUpFormat".into(), json!({"frame": id.0, "point": [p.x, p.y]}))];
+ }
vec![Action::Exec("object.matchAttributes".into(), json!({"from": id.0}))]
}
fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {