diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index c8c479bc03..9cfedcb7a8 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -126,7 +126,7 @@ pub fn specs() -> Vec { "Eyedropper", [], None, - "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes) from `source` to ids (default: highlighted characters while editing type, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art) → {ids}", + "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art) → {ids}", has_doc, copy_from ), @@ -1103,14 +1103,17 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { if !reverse && !defaults_only { s.eyedropper_sample = Some(node); } - let range = range.filter(|(id, _, _)| targets.contains(id)); // The highlighted characters' type objects and ranges: after Select All in threaded text, all - // the text of every frame of the story. + // the text of every frame of the story, except a frame the attributes come from, in place of + // the object selection. let story = super::textedit::editing_story(s); let ranges: Vec<(NodeId, Option<(usize, usize)>)> = match range { - Some((id, _, _)) if story.contains(&id) => story.iter().map(|f| (*f, None)).collect(), - Some((id, start, end)) => vec![(id, Some((start, end)))], - None => vec![], + Some((id, _, _)) if story.contains(&id) => { + targets.clear(); + story.iter().copied().filter(|f| Some(*f) != source).map(|f| (f, None)).collect() + } + Some((id, start, end)) if targets.contains(&id) => vec![(id, Some((start, end)))], + _ => vec![], }; // Character styles cannot represent object transparency. Refuse before even changing // paint defaults; applying it to the object would also alter the unselected characters. @@ -1128,7 +1131,7 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { if !reverse { picked.to_defaults(s, &attrs.appearance); } - if targets.is_empty() || attrs.is_empty() { + if (targets.is_empty() && ranges.is_empty()) || attrs.is_empty() { return Ok(json!({ "ids": [] })); } if !ranges.is_empty() { diff --git a/crates/engine/src/tests/textedit.rs b/crates/engine/src/tests/textedit.rs index dde0c4bf5f..ed3e2eac39 100644 --- a/crates/engine/src/tests/textedit.rs +++ b/crates/engine/src/tests/textedit.rs @@ -1613,6 +1613,269 @@ fn the_eyedropper_styles_the_whole_story_that_select_all_selected() { } } +/// A red rectangle outside the story of [`threaded_story_edited_in_its_second_frame`], to pick up +/// from at (525, 325), with the Type tool editing frame `b` at its start again. +fn red_source(s: &mut Session, b: NodeId) { + let source = s.execute("shape.rectangle", &json!({"x": 500, "y": 300, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + s.execute("paint.setFill", &json!({"ids": [source], "color": "#ff0000"})).unwrap(); + s.execute("select.set", &json!({"ids": [b.0]})).unwrap(); + s.set_tool_option("textSelection", &json!({"editing": b.0, "anchor": 0, "caret": 0})); +} + +fn all_red(s: &Session, id: NodeId) -> bool { + obj(s, id).runs.iter().all(|r| r.style.fill.color().is_some_and(|c| c.to_hex() == "#ff0000")) +} + +fn any_red(s: &Session, id: NodeId) -> bool { + obj(s, id).runs.iter().any(|r| r.style.fill.color().is_some_and(|c| c.to_hex() == "#ff0000")) +} + +/// A click and a Shift-click of the Eyedropper on the rectangle of [`red_source`]. +fn eyedropper_picks() -> [Mods; 2] { + [Mods::default(), Mods { shift: true, ..Default::default() }] +} + +fn pick_red_source(s: &mut Session, mods: Mods) { + s.pointer(&PointerEvent::new(PointerKind::Down, 525.0, 325.0).with_mods(mods), ViewInfo::default()).unwrap(); +} + +fn highlights(s: &mut Session) -> usize { + s.overlays(ViewInfo::default()).iter().filter(|o| matches!(o, vectorcraft_tools::Overlay::Highlight { .. })).count() +} + +#[test] +fn switching_to_the_eyedropper_keeps_the_whole_story_selected() { + for mods in eyedropper_picks() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + red_source(&mut s, b); + s.execute("select.all", &json!({})).unwrap(); + let highlighted = highlights(&mut s); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + assert_eq!(s.tool_options()["story"], json!([a.0, b.0])); + assert!(highlights(&mut s) >= highlighted, "the Eyedropper highlights the text of both frames"); + let undo = s.doc().unwrap().history.undo.len(); + pick_red_source(&mut s, mods); + assert!(all_red(&s, a) && all_red(&s, b), "every frame takes the pick"); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "one undo step"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(!any_red(&s, a) && !any_red(&s, b), "one undo takes the pick back from every frame"); + s.select_tool("type", ViewInfo::default()).unwrap(); + let o = s.tool_options(); + assert_eq!((&o["editing"], &o["story"]), (&json!(a.0), &json!([a.0, b.0])), "back in the Type tool the story stays selected"); + s.tool_text("x", ViewInfo::default()).unwrap(); + assert_eq!(format!("{}{}", obj(&s, a).plain_text(), obj(&s, b).plain_text()), "x", "typing replaces the whole story"); + } +} + +#[test] +fn a_selection_inside_one_threaded_frame_stays_in_that_frame_under_the_eyedropper() { + for mods in eyedropper_picks() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + red_source(&mut s, b); + s.set_tool_option("select", &json!({"start": 0, "end": 4})); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + assert!(s.tool_options().get("story").is_none()); + let undo = s.doc().unwrap().history.undo.len(); + pick_red_source(&mut s, mods); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1); + assert_eq!(obj(&s, b).runs[0].text.len(), 4, "only the selected characters take the pick"); + assert!(any_red(&s, b) && !all_red(&s, b) && !any_red(&s, a)); + s.select_tool("type", ViewInfo::default()).unwrap(); + let o = s.tool_options(); + assert_eq!((o["editing"].as_u64(), o["start"].as_u64(), o["end"].as_u64()), (Some(b.0), Some(0), Some(4))); + } +} + +#[test] +fn an_eyedropper_pick_on_the_whole_story_styles_locked_and_hidden_frames() { + for command in ["object.lock", "object.hide"] { + for held_first in [false, true] { + for mods in eyedropper_picks() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + let (held, other) = if held_first { (a, b) } else { (b, a) }; + s.execute(command, &json!({"ids": [held.0]})).unwrap(); + red_source(&mut s, other); + assert_eq!(s.execute("select.all", &json!({})).unwrap()["story"], json!([a.0, b.0])); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + let undo = s.doc().unwrap().history.undo.len(); + pick_red_source(&mut s, mods); + assert!(all_red(&s, other), "{command}: the other frame takes the pick"); + assert!(all_red(&s, held), "{command}: the held frame takes the pick"); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "{command}: one undo step"); + } + } + } +} + +#[test] +fn an_eyedropper_pick_from_a_frame_of_the_selected_story_styles_the_other_frames() { + for source_first in [false, true] { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + let (source, other) = if source_first { (a, b) } else { (b, a) }; + s.execute("text.setStyle", &json!({"ids": [source.0], "fill": "#ff0000"})).unwrap(); + assert!(all_red(&s, source) && !any_red(&s, other)); + s.execute("select.set", &json!({"ids": [b.0]})).unwrap(); + s.set_tool_option("textSelection", &json!({"editing": b.0, "anchor": 0, "caret": 0})); + s.execute("select.all", &json!({})).unwrap(); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + let undo = s.doc().unwrap().history.undo.len(); + let r = s.execute("appearance.copyFrom", &json!({"source": source.0})).unwrap(); + assert_eq!(r, json!({"ids": [other.0]})); + assert!(all_red(&s, other) && all_red(&s, source)); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1); + } +} + +/// Whether a character in the frame that `text.thread.add` places at [`THREADED_AT`] is highlighted. +fn third_frame_highlighted(s: &mut Session) -> bool { + let in_frame = |o: &vectorcraft_tools::Overlay| matches!(o, vectorcraft_tools::Overlay::Highlight { quad, color: [60, 120, 255, 90] } if quad.iter().all(|p| p.x > 690.0)); + s.overlays(ViewInfo::default()).iter().any(in_frame) +} + +/// Where a third frame of the story of [`threaded_story_edited_in_its_second_frame`] goes, clear +/// of its other frames. +const THREADED_AT: [f64; 2] = [700.0, 10.0]; + +#[test] +fn a_frame_threaded_into_the_selected_story_is_highlighted_and_takes_the_edit() { + for mods in eyedropper_picks() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + red_source(&mut s, b); + s.execute("select.all", &json!({})).unwrap(); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + let c = s.execute("text.thread.add", &json!({"from": a.0, "before": true, "at": THREADED_AT})).unwrap()["id"].as_u64().unwrap(); + let c = NodeId(c); + assert!(!obj(&s, c).plain_text().is_empty(), "the story starts in the new frame"); + assert!(third_frame_highlighted(&mut s), "the new frame's text is highlighted"); + pick_red_source(&mut s, mods); + assert!(all_red(&s, a) && all_red(&s, b) && all_red(&s, c), "every frame takes the pick"); + s.select_tool("type", ViewInfo::default()).unwrap(); + assert!(third_frame_highlighted(&mut s), "back in the Type tool too"); + s.tool_text("x", ViewInfo::default()).unwrap(); + let text = [a, b, c].map(|f| obj(&s, f).plain_text()).concat(); + assert_eq!(text, "x", "typing replaces the text of every frame"); + } +} + +/// After Select All in the story of [`threaded_story_edited_in_its_second_frame`], a frame threaded +/// in before the edited one takes the whole story, and the edited frame holds no text. +fn selected_story_moved_into_a_new_frame(s: &mut Session, a: NodeId, b: NodeId) -> NodeId { + let rect = [THREADED_AT[0], THREADED_AT[1], 400.0, 600.0]; + let c = NodeId(s.execute("text.thread.add", &json!({"from": a.0, "before": true, "rect": rect})).unwrap()["id"].as_u64().unwrap()); + assert!(obj(s, a).plain_text().is_empty() && obj(s, b).plain_text().is_empty(), "the new frame holds the whole story"); + assert!(!obj(s, c).plain_text().is_empty()); + c +} + +#[test] +fn a_story_that_left_the_edited_frame_is_highlighted_and_typing_replaces_it() { + for through_eyedropper in [false, true] { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + s.execute("select.all", &json!({})).unwrap(); + if through_eyedropper { + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + } + let c = selected_story_moved_into_a_new_frame(&mut s, a, b); + assert!(third_frame_highlighted(&mut s), "through the Eyedropper: {through_eyedropper}"); + if through_eyedropper { + s.select_tool("type", ViewInfo::default()).unwrap(); + assert!(third_frame_highlighted(&mut s), "back in the Type tool"); + } + s.tool_text("x", ViewInfo::default()).unwrap(); + assert_eq!([a, b, c].map(|f| obj(&s, f).plain_text()).concat(), "x", "through the Eyedropper: {through_eyedropper}"); + } +} + +#[test] +fn delete_replaces_a_story_that_left_the_edited_frame() { + for k in [ToolKey::Backspace, ToolKey::Delete] { + let (mut s, a, b, story) = threaded_story_edited_in_its_second_frame(); + s.execute("select.all", &json!({})).unwrap(); + let c = selected_story_moved_into_a_new_frame(&mut s, a, b); + let steps = undo_labels(&s).len(); + key(&mut s, k, Mods::default()); + key(&mut s, ToolKey::Escape, Mods::default()); + assert_eq!([a, b, c].map(|f| obj(&s, f).plain_text()).concat(), "", "{k:?} empties every frame"); + assert_eq!(undo_labels(&s).len(), steps + 1, "{k:?}: one undo step"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!([a, b, c].map(|f| obj(&s, f).plain_text()).concat(), story); + } +} + +#[test] +fn delete_in_a_story_that_holds_no_text_records_no_undo_step() { + for k in [ToolKey::Backspace, ToolKey::Delete] { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + s.execute("select.all", &json!({})).unwrap(); + key(&mut s, ToolKey::Delete, Mods::default()); + s.execute("select.all", &json!({})).unwrap(); + assert_eq!(s.tool_options()["story"], json!([a.0, b.0])); + let steps = undo_labels(&s).len(); + key(&mut s, k, Mods::default()); + key(&mut s, ToolKey::Escape, Mods::default()); + assert_eq!(undo_labels(&s).len(), steps, "{k:?}"); + } +} + +#[test] +fn a_type_step_keeps_a_story_that_left_the_edited_frame_selected() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + s.execute("select.all", &json!({})).unwrap(); + let c = selected_story_moved_into_a_new_frame(&mut s, a, b); + // Alt+Right steps the tracking of the selected text, not the kerning at a caret. + key(&mut s, ToolKey::Right, Mods { alt: true, ..Mods::default() }); + assert!(obj(&s, c).runs.iter().all(|r| r.style.tracking > 0.0), "every character of the story takes the step"); + // A key that does nothing leaves it selected as well. + key(&mut s, ToolKey::BracketLeft, Mods::default()); + assert!(third_frame_highlighted(&mut s)); + // The story stays the target of a fill and of a switch to the Eyedropper. + s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); + assert!(all_red(&s, c), "the fill reaches the story"); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + assert!(third_frame_highlighted(&mut s), "the Eyedropper keeps the story"); +} + +#[test] +fn a_frame_that_left_the_selected_story_is_not_highlighted_and_leaves_the_edit() { + for mods in eyedropper_picks() { + let (mut s, a, b, _) = threaded_story_edited_in_its_second_frame(); + let c = s.execute("text.thread.add", &json!({"from": b.0, "at": THREADED_AT})).unwrap()["id"].as_u64().unwrap(); + let c = NodeId(c); + red_source(&mut s, b); + assert_eq!(s.execute("select.all", &json!({})).unwrap()["story"], json!([a.0, b.0, c.0])); + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + s.execute("text.thread.break", &json!({"id": b.0, "port": "out"})).unwrap(); + s.execute("text.setText", &json!({"id": c.0, "text": "Kept"})).unwrap(); + assert!(!third_frame_highlighted(&mut s), "the frame that left has no highlight"); + pick_red_source(&mut s, mods); + assert!(all_red(&s, a) && all_red(&s, b), "the frames still threaded take the pick"); + assert!(!any_red(&s, c), "the frame that left stays as it is"); + s.select_tool("type", ViewInfo::default()).unwrap(); + s.tool_text("x", ViewInfo::default()).unwrap(); + assert_eq!(obj(&s, c).plain_text(), "Kept", "typing leaves the frame that left"); + } +} + +#[test] +fn typing_after_a_thread_is_removed_leaves_the_frame_that_left_the_story() { + for through_eyedropper in [false, true] { + let (mut s, _, b, _) = threaded_story_edited_in_its_second_frame(); + s.execute("select.all", &json!({})).unwrap(); + if through_eyedropper { + s.select_tool("eyedropper", ViewInfo::default()).unwrap(); + } + s.execute("text.thread.remove", &json!({})).unwrap(); + assert_eq!(s.execute("text.thread.info", &json!({})).unwrap(), json!([])); + if through_eyedropper { + s.select_tool("type", ViewInfo::default()).unwrap(); + } + let left = obj(&s, b).plain_text(); + assert!(!left.is_empty()); + s.tool_text("x", ViewInfo::default()).unwrap(); + assert_eq!(obj(&s, b).plain_text(), left, "through the Eyedropper: {through_eyedropper}"); + } +} + #[test] fn typing_over_the_whole_story_replaces_every_frames_text_in_one_step() { let (mut s, a, b, story) = threaded_story_edited_in_its_second_frame(); diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 66d84a925b..2d85d620fe 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -131,8 +131,9 @@ impl Session { if self.tool.id() == id { return Ok(()); } - // Sampling type keeps its highlighted characters as the target. Capture before the - // Type tool deactivates (which commits typing and clears its editing state). + // Sampling type keeps its highlighted characters as the target, and a whole story that + // Select All selected. Capture before the Type tool deactivates (which commits typing and + // clears its editing state). let is_type = |id: &str| matches!(id, "type" | "areaType" | "typeOnPath" | "verticalType" | "verticalAreaType" | "verticalTypeOnPath"); let text_selection = ((id == "eyedropper" && is_type(self.tool.id())) || (self.tool.id() == "eyedropper" && is_type(id))) .then(|| self.tool.options()) diff --git a/crates/tools/src/text.rs b/crates/tools/src/text.rs index 9dd96a1bf9..0bc29a5587 100644 --- a/crates/tools/src/text.rs +++ b/crates/tools/src/text.rs @@ -174,9 +174,10 @@ pub struct TypeTool { /// Caret and selection anchor (byte offsets into the plain text). caret: usize, anchor: usize, - /// After Select All in a frame of threaded text: the story's frames in thread order, the edited - /// one included. While the selection is the edited frame's whole text, the text of the other - /// frames is selected too. Empty otherwise. + /// After Select All in a frame of threaded text: the story's frames in thread order then, the + /// edited one included. While the selection is the edited frame's whole text and this holds the + /// edited frame, the text of the other frames of its current thread is selected too. Empty + /// otherwise. story: Vec, /// Horizontal position kept by Up/Down (text space). goal_x: Option, @@ -230,8 +231,8 @@ impl TypeTool { return None; } let id = self.editing?; - let (attribute, by) = plain::step_key(key, mods.shift, a == b, vertical)?; let story = !self.story_others(cx).is_empty(); + let (attribute, by) = plain::step_key(key, mods.shift, a == b && !story, vertical)?; let mut out = self.commit(); let by = if mods.cmd { by * 5.0 } else { by }; // With the whole story selected, `type.step` steps the text of every frame of it. @@ -441,8 +442,8 @@ impl TypeTool { } /// The other frames whose whole text is selected along with the edited frame's after Select - /// All in threaded text ([`Self::story`]): none once the selection is not all of the edited - /// frame's text. + /// All in threaded text ([`Self::story`]), read from the document's current thread: none once + /// the selection is not all of the edited frame's text. fn story_others(&self, cx: &ToolContext) -> Vec { let Some(id) = self.editing.filter(|id| self.story.contains(id)) else { return vec![] }; let Some(t) = Self::text(cx, id) else { return vec![] }; @@ -450,7 +451,22 @@ impl TypeTool { if a != 0 || b < edit::runs_len(&t.runs) { return vec![]; } - self.story.iter().copied().filter(|f| *f != id && Self::text(cx, *f).is_some()).collect() + cx.doc.story_of(id).into_iter().filter(|f| *f != id).collect() + } + + /// Whether the whole story is selected ([`Self::story_others`]) and its other frames hold text. + /// The story stays selected when the edited frame holds no text, as after a frame threaded in + /// before it took the text. + fn story_selected(&self, cx: &ToolContext) -> bool { + self.story_others(cx).into_iter().any(|f| Self::text(cx, f).is_some_and(|o| edit::runs_len(&o.runs) > 0)) + } + + /// Put back the caret and anchor `selected` that a key clamped to the edited frame's text, when + /// the key leaves the whole story selected. + fn keep_story_offsets(&mut self, story: bool, selected: (usize, usize)) { + if story { + (self.caret, self.anchor) = selected; + } } /// Move the caret (Shift keeps the anchor). Moving ends the typing session. diff --git a/crates/tools/src/text/tool.rs b/crates/tools/src/text/tool.rs index 5634cf5a1f..1e9b1be88c 100644 --- a/crates/tools/src/text/tool.rs +++ b/crates/tools/src/text/tool.rs @@ -197,11 +197,14 @@ impl Tool for TypeTool { }; let text = t.plain_text(); let len = text.len(); + let story = self.story_selected(cx); + let selected = (self.caret, self.anchor); self.caret = self.caret.min(len); self.anchor = self.anchor.min(len); let (a, b) = self.sel(); // Alt+arrows step the type by the Preferences › Type increments (Cmd/Ctrl too: five steps). if let Some(out) = self.step_attribute(cx, key, mods, a, b, t.vertical) { + self.keep_story_offsets(story, selected); return out; } let word = mods.cmd || mods.alt; @@ -233,7 +236,7 @@ impl Tool for TypeTool { } ToolKey::Enter => self.replace(cx, if mods.shift { "\u{2028}" } else { "\n" }, None), ToolKey::Tab => self.replace(cx, "\t", None), - ToolKey::Backspace | ToolKey::Delete if a != b => self.replace(cx, "", None), + ToolKey::Backspace | ToolKey::Delete if a != b || story => self.replace(cx, "", None), ToolKey::Backspace if self.caret > 0 => { self.anchor = if word { edit::prev_word(&text, self.caret) } else { edit::prev_char(&text, self.caret) }; self.replace(cx, "", None) @@ -313,7 +316,10 @@ impl Tool for TypeTool { let to = if mods.cmd { len } else { vectorcraft_text::line_end_of(&lay, self.caret) }; self.move_to(to, mods.shift) } - _ => vec![], + _ => { + self.keep_story_offsets(story, selected); + vec![] + } } } fn ime_preedit(&mut self, cx: &ToolContext, text: &str, active_chars: Option>) -> Vec { @@ -546,6 +552,12 @@ impl Tool for TypeTool { { self.start_editing(NodeId(id), b); self.anchor = a; + // The frames of a threaded story whose whole text Select All selected. + let story: Vec = + v.get("story").and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_u64).map(NodeId).collect(); + if story.len() >= 2 && story.contains(&NodeId(id)) { + self.story = story; + } } } "prevTool" | "previousTool" => { @@ -672,7 +684,10 @@ impl Tool for TypeTool { for q in vectorcraft_text::selection_quads(&lay, a, b) { o.push(Overlay::Highlight { quad: q.map(|p| t.xf * p), color: [60, 120, 255, 90] }); } - // The whole story is selected: the other frames' text is highlighted too. + } + // The whole story is selected: the other frames' text is highlighted too, also when the + // edited frame holds no text. + if self.preedit.is_none() { for f in self.story_others(cx) { let Some(other) = Self::text(cx, f) else { continue }; let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), other); diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index 7e68824c19..34a3e006fe 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -540,11 +540,13 @@ static CLIP_RUNS: Mutex> = Mutex::new(None); fn text_copy(app: &mut VectorcraftApp) -> bool { let Some((id, a, b)) = text_editing(app) else { return false }; - if a == b { + let story = text_story(app); + // An empty selection has nothing to copy, unless the story's text is in the other frames. + if a == b && (story.is_none() || app.session.active().is_none_or(|st| st.doc.story_text(id).is_empty())) { return false; } // After Select All in threaded text: the whole story. - let range = if text_story(app).is_some() { json!({"id": id.0, "story": true}) } else { json!({"id": id.0, "start": a, "end": b}) }; + let range = if story.is_some() { json!({"id": id.0, "story": true}) } else { json!({"id": id.0, "start": a, "end": b}) }; let Ok(r) = app.session.execute("text.getRange", &range) else { return false }; let runs = r["runs"].clone(); app.session.set_tool_option("copy", &runs); diff --git a/crates/ui-egui/src/panels/character/tests.rs b/crates/ui-egui/src/panels/character/tests.rs index 2a35193852..e6927f843a 100644 --- a/crates/ui-egui/src/panels/character/tests.rs +++ b/crates/ui-egui/src/panels/character/tests.rs @@ -1244,6 +1244,50 @@ fn snap_to_glyph_options_scroll_into_view_and_turn_snapping_on() { assert!(!app.session.prefs.glyph_snap.anchors, "the options take clicks once it is on"); } +/// Copy and Cut take a selected story after a frame threaded in before the edited one took its whole +/// text. +#[test] +fn copy_and_cut_take_a_story_that_left_the_edited_frame() { + for cut in [false, true] { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 600, "height": 300})).unwrap(); + let story = "The quick brown fox jumps over the lazy dog and keeps running far beyond the first frame. ".repeat(4); + let area = json!({"x": 10, "y": 10, "text": story, "size": 12, "area": {"width": 150, "height": 60}}); + let a = app.run("text.create", area).unwrap()["id"].as_u64().unwrap(); + let b = app.run("shape.rectangle", json!({"x": 200, "y": 10, "width": 150, "height": 200})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + app.run("text.thread.create", json!({})).unwrap(); + app.session.select_tool("type", Default::default()).unwrap(); + app.session.set_tool_option("textSelection", &json!({"editing": a, "anchor": 0, "caret": 0})); + app.run("select.all", json!({})).unwrap(); + let c = app.run("text.thread.add", json!({"from": a, "before": true, "rect": [700, 10, 400, 600]})).unwrap()["id"].as_u64().unwrap(); + let text = |app: &VectorcraftApp, id: u64| match &app.session.active().unwrap().doc.node(NodeId(id)).unwrap().kind { + NodeKind::Text(t) => t.plain_text(), + _ => panic!("not text"), + }; + assert_eq!((text(&app, a), text(&app, b), text(&app, c)), (String::new(), String::new(), story.clone())); + assert!(intercept_text_command(&mut app, if cut { "edit.cut" } else { "edit.copy" }).is_some()); + let copied: Vec = app + .session + .clipboard + .nodes + .iter() + .filter_map(|n| match &n.kind { + NodeKind::Text(t) => Some(t.plain_text()), + _ => None, + }) + .collect(); + assert_eq!(copied, std::slice::from_ref(&story), "cut: {cut}"); + assert_eq!(text(&app, c).is_empty(), cut); + if cut { + // A story that holds no text has nothing to copy, so Cut does not run its delete. + app.run("select.all", json!({})).unwrap(); + assert_eq!(text_story(&app).map(|frames| frames.len()), Some(3)); + assert!(!text_copy(&mut app)); + } + } +} + /// After Select All in a frame of threaded text, the Character and Paragraph panels and Copy act on /// the text of every frame of the story. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 3283eea2ab..c3890b89fb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5015,7 +5015,12 @@ and Cut take. Typing, Delete and Cut replace the whole story as one undo step (` frames whose text goes), and a fill, stroke, `type.step` or Character or Paragraph panel change applies to the text of every frame (the Character panel sends `text.setRangeStyle {id, story: true}`, which styles every frame's text in one undo step). Remove Line Breaks, Remove Paragraph Breaks and Convert to Text also act on the text of every frame, as -one undo step. A caret move or a click ends the story selection. +one undo step. A caret move or a click ends the story selection. Switching to the Eyedropper keeps the story selected, +and switching back to a Type tool restores it. `appearance.copyFrom` and `paint.sampleColor` then apply to the text of +every frame as one undo step, and `appearance.copyFrom` leaves out a frame that is its `source`. While the story stays +selected, its frames are the ones threaded with the edited frame at that moment: a frame that `text.thread.add` adds is +highlighted and takes the edit, and a frame that leaves the thread is not highlighted and keeps its text. The story +stays selected when a frame added before the edited frame takes all of its text. Once a thread is removed, typing replaces the text of the edited frame only. ```json {"name":"press_key","arguments":{"key":"A","mods":{"cmd":true}}} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 757fb0bb35..f128c1e9d8 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -735,6 +735,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The function key shortcuts for Brushes, Color, Layers, Info, Gradient, Stroke, Attributes, Graphic Styles, Appearance, Align, Transform, Pathfinder, Transparency, and Symbols activate a background tab on the first press, hide its expanded dock or floating group when that tab is in front, and restore the group with all its tabs together on the next press; in an icon column they open and close the flyout while keeping the icons. A reassigned chord keeps that behavior, and Window > a hidden sibling restores the group. - Cmd/Ctrl+A follows the keyboard: in a panel, dialog or search field it selects the field's text, while the Type tool edits it selects all of that text (also `select.all` over MCP), and only otherwise every object. On macOS the menu bar's Select All, Cut, Copy and Paste (keys or clicks) act on a focused field too, and elsewhere the in-window menus' do: the field that had the keyboard when the menu opened gets them, with its selection, and the keyboard back (#516). In a frame of threaded text, Select All selects the whole story, highlighted in every frame: Copy and Cut take all of it, typing or Delete replaces it as one undo step, and a fill, a size step or a Character or Paragraph panel change applies to every frame's text (VectorCraft's own behavior; `textedit::select_all_in_a_threaded_frame_selects_the_whole_story`, `textedit::typing_over_the_whole_story_replaces_every_frames_text_in_one_step`). - With the whole story of threaded text selected by Select All, Remove Line Breaks, Remove Paragraph Breaks and Type › Bullets and Numbering › Convert to Text act on the text of every frame as one undo step, and the story stays selected after Convert to Text; a selection inside one frame changes only that frame (VectorCraft's own behavior; `textedit::remove_breaks_takes_the_whole_story_that_select_all_selected`, `textedit::convert_to_text_takes_the_whole_story_that_select_all_selected`). + - Switching from a Type tool to the Eyedropper keeps a whole story selected by Select All: a pick applies to the text of every frame as one undo step, and switching back restores the story selection (VectorCraft's own behavior; `textedit::switching_to_the_eyedropper_keeps_the_whole_story_selected`). - While the Type tool edits text, a character typed with AltGr is typed and runs no command. Firefox on Windows reports AltGr as Ctrl and Alt held, so in the web build AltGr+L (ł on a Polish layout) does not also open Layer Options for a new layer, and AltGr+Q (@ on a German layout) does not also run Reset Tracking and Kerning. A Ctrl+Alt chord that types no character runs its command. - On a layout without Latin letters, a one-key shortcut goes by the position of the key that typed the character, in the web build too, where the character arrives before its key press: on a Russian layout the P key (`з`) chooses the Pen, and two keys pressed in one frame each run their own shortcut. - With the Artboard tool, Cmd/Ctrl+A after a click on a row of the Artboards panel selects every artboard, as the macOS menu bar's Select All does then; the active artboard stays active, and the art's selection does not change. After a press outside the panel's list, Cmd/Ctrl+A selects every object again. It used to select every object after a click in the panel too. Public reference: [Select artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/add-edit-artboards/select-artboards.html).