diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index e3d2a13d64..4c823d1ffa 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -167,6 +167,7 @@ impl VectorcraftApp { forwarded_modifiers: None, forwarded_modifiers_held: false, forwarded_frame: false, + forwarded_clipboard: false, synthetic_modifiers: false, ime_marked: None, ime_context: Default::default(), diff --git a/crates/ui-egui/src/app/input.rs b/crates/ui-egui/src/app/input.rs index 95f719d08b..5b7310d56a 100644 --- a/crates/ui-egui/src/app/input.rs +++ b/crates/ui-egui/src/app/input.rs @@ -214,6 +214,7 @@ impl VectorcraftApp { raw.events.insert(0, egui::Event::ModifiersChanged(self.host_modifiers)); } self.forwarded_frame = !self.forwarded.is_empty(); + self.forwarded_clipboard = self.forwarded.iter().any(|e| matches!(e, egui::Event::Copy | egui::Event::Cut)); if !self.forwarded.is_empty() { if let Some(m) = self.forwarded_modifiers.take() { raw.events.push(egui::Event::ModifiersChanged(m)); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0b8ee67183..68fd000e5f 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -304,6 +304,9 @@ pub struct VectorcraftApp { /// This host iteration's input carries forwarded keys: they are the main window's although /// its OS window doesn't have the keyboard (see `shortcuts::handle`). pub(crate) forwarded_frame: bool, + /// The forwarded keys of this host iteration hold a Copy or Cut: it copies the art, not text + /// selected in this window's labels (see `shortcuts::handle_clipboard`). + pub(crate) forwarded_clipboard: bool, /// Synthetic input set the modifiers egui holds (see [`Self::raw_input_hook`]). synthetic_modifiers: bool, /// The marked text the system IME last sent (`None` once it commits or clears). When the Type diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index ee40c7793e..ede8deaa1e 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -122,6 +122,9 @@ pub fn invoke_from_system_menu(app: &mut VectorcraftApp, ctx: &egui::Context, id if let Some((_, e)) = label_event { ctx.input_mut(|i| i.events.push(e)); } + // The labels' text replaces the formats of an earlier Copy or Cut not written yet, even + // in a frame whose keys are not this window's. + app.drop_unwritten_formats(); } None if id == "select.all" && crate::panels::artboards::selects_all(app, ctx) => crate::panels::artboards::select_all(app), None => invoke(app, id, p), diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 0b93ed3a84..2d815e7e3f 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -808,7 +808,7 @@ fn handle_clipboard(app: &mut VectorcraftApp, ctx: &egui::Context, textless_past // sent them on (a floating document's): those copy the art. The menu bar's Copy and Cut have // left theirs to the labels already. let mut clip = vec![]; - let forwarded = app.forwarded_frame && ctx.viewport_id() == egui::ViewportId::ROOT; + let forwarded = app.forwarded_clipboard && ctx.viewport_id() == egui::ViewportId::ROOT; let to_labels = |e: egui::Event, id| ctx.input(|i| i.events.contains(&e)) && (left_to_labels(ctx) == Some(id) || (!forwarded && leave_to_labels(ctx, id))); let (labels_copy, labels_cut) = (to_labels(egui::Event::Copy, "edit.copy"), to_labels(egui::Event::Cut, "edit.cut")); diff --git a/crates/ui-egui/src/shortcuts/labels.rs b/crates/ui-egui/src/shortcuts/labels.rs index 949dda133c..1865ca1821 100644 --- a/crates/ui-egui/src/shortcuts/labels.rs +++ b/crates/ui-egui/src/shortcuts/labels.rs @@ -12,6 +12,7 @@ fn after_labels_id() -> egui::Id { /// Set when a label in a window of its own (a floating panel's) copied its selected text: the /// window then sends the Copy or Cut on to the main window ([`crate::panel_docking::forward_keys`]). +/// It lasts until the main window's next pass starts. fn copied_in_window_id() -> egui::Id { egui::Id::unique("labels-copied-in-window") } @@ -71,11 +72,21 @@ impl egui::Plugin for CopyAfterLabels { "CopyAfterLabels" } + /// The windows of their own run their passes inside the main window's pass, and their Copy or + /// Cut is sent on in that pass: a copy noted before it is not theirs. + fn on_begin_pass(&mut self, ui: &mut egui::Ui) { + if ui.ctx().viewport_id() == egui::ViewportId::ROOT { + take_copied_in_window(ui.ctx()); + } + } + fn on_end_pass(&mut self, ui: &mut egui::Ui) { let ctx = ui.ctx(); let copied = ctx.output(|o| o.commands.iter().any(|c| matches!(c, egui::OutputCommand::CopyText(_)))); + // A field with the keyboard copies its own text, and its window sends nothing on. if ctx.viewport_id() != egui::ViewportId::ROOT && copied + && ctx.memory(|m| m.focused().is_none()) && ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Copy | egui::Event::Cut))) { ctx.data_mut(|d| d.insert_temp(copied_in_window_id(), true)); diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 4fad102f73..87e63c810e 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -1323,6 +1323,40 @@ fn copy_and_paste_events_use_the_system_clipboard() { assert_eq!(app.session.doc().unwrap().doc.layers[0].children().unwrap().len(), 8); } +/// #8432: a window of its own (a floating panel's) notes that its labels copied the text a Copy +/// asked for, so that the Copy it sends on to the main window copies nothing more. A field with +/// the keyboard copying its own text is not noted, and a note lasts only until the main window's +/// next pass, so it never drops a later Copy from another window. +#[test] +fn a_window_notes_only_its_labels_copies_until_the_next_main_window_pass() { + let ctx = egui::Context::default(); + watch_label_copies(&ctx); + let main_window_pass = || ctx.run_ui(egui::RawInput::default(), |_| {}).drop_without_applying_deltas(); + main_window_pass(); + let window = egui::ViewportId::from_hash_of("floating panel"); + let mut window_input = egui::RawInput { viewport_id: window, events: vec![egui::Event::Copy], ..Default::default() }; + window_input.viewports.insert(window, egui::ViewportInfo { parent: Some(egui::ViewportId::ROOT), ..Default::default() }); + // `field`: the text is copied by a field with the keyboard instead of a label. + let copy_in_window = |field: bool| { + ctx.run_ui(window_input.clone(), |ui| { + if field { + let mut text = String::from("234 pt"); + ui.text_edit_singleline(&mut text).request_focus(); + } + ui.ctx().copy_text("234 pt".into()); + }) + .drop_without_applying_deltas(); + }; + copy_in_window(false); + assert!(take_copied_in_window(&ctx), "the window's label copied the text"); + assert!(!take_copied_in_window(&ctx), "once"); + copy_in_window(false); + main_window_pass(); + assert!(!take_copied_in_window(&ctx), "the main window's next pass forgets the note"); + copy_in_window(true); + assert!(!take_copied_in_window(&ctx), "a field's copy is not noted"); +} + /// While a grid is dragged out, ↑/↓ change its rows and ←/→ its columns. #[test] fn arrows_while_dragging_a_grid_change_its_rows_and_columns() { diff --git a/crates/ui-egui/src/tests/selectall.rs b/crates/ui-egui/src/tests/selectall.rs index 39994d3f86..8b08c79f51 100644 --- a/crates/ui-egui/src/tests/selectall.rs +++ b/crates/ui-egui/src/tests/selectall.rs @@ -15,6 +15,8 @@ struct App { app: VectorcraftApp, ctx: egui::Context, time: f64, + /// The window has the keyboard. + focused: bool, } impl App { @@ -24,7 +26,7 @@ impl App { app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); app.run("shape.rectangle", json!({"x": 200, "y": 150, "width": 20, "height": 20})).unwrap(); app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 37, "height": 40})).unwrap(); - let mut a = Self { app, ctx: egui::Context::default(), time: 0.0 }; + let mut a = Self { app, ctx: egui::Context::default(), time: 0.0, focused: true }; for _ in 0..3 { a.frame(vec![]); } @@ -38,6 +40,7 @@ impl App { let raw = egui::RawInput { events, time: Some(self.time), + focused: self.focused, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 850.0))), ..Default::default() }; @@ -273,36 +276,47 @@ fn text_rect(out: &egui::FullOutput, text: &str) -> Rect { .unwrap_or_else(|| panic!("no {text:?} painted")) } +/// Document Info open on its Objects category, after a few frames to lay it out: the last frame. +fn show_document_info(a: &mut App) -> egui::FullOutput { + a.app.run("window.panel", json!({"panel": "docInfo"})).unwrap(); + crate::panels::set_pstate(&a.ctx, "docinfo-category", "objects".to_string()); + let mut out = a.frame(vec![]); + for _ in 0..3 { + out = a.frame(vec![]); + } + out +} + +/// Drag across the label text `text` painted in `out`, selecting it: the frame after the drag. +fn select_label_text(a: &mut App, out: &egui::FullOutput, text: &str) -> egui::FullOutput { + let r = text_rect(out, text); + let (from, to) = (r.left_center() + vec2(1.0, 0.0), r.right_center() - vec2(1.0, 0.0)); + a.frame(vec![Event::PointerMoved(from)]); + a.frame(vec![click(from, true)]); + for k in 1..=4 { + a.frame(vec![Event::PointerMoved(from + (to - from) * k as f32 / 4.0)]); + } + a.frame(vec![click(to, false)]); + a.frame(vec![]) +} + +/// Cmd+C or Cmd+X (`e`): the chord's frame, then the frame after it, when the keys are let go. +fn clipboard_chord(a: &mut App, e: Event) -> (egui::FullOutput, egui::FullOutput) { + let out = a.frame(vec![Event::ModifiersChanged(Modifiers::COMMAND), e]); + (out, a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)])) +} + /// #8432: with a Document Info value's text selected, Copy and Cut (the keys or the menu bar's /// items) copy that text and leave the art. With nothing selected in the labels, or when the /// selected label is not drawn, Copy copies the art. #[test] fn copy_and_cut_copy_the_text_selected_in_a_panel_label() { let mut a = App::new(); - a.app.run("window.panel", json!({"panel": "docInfo"})).unwrap(); - crate::panels::set_pstate(&a.ctx, "docinfo-category", "objects".to_string()); + let out = show_document_info(&mut a); // The two rectangles' outlines: 2 × (20 + 20) + 2 × (37 + 40). let length = "234 pt"; - let mut out = a.frame(vec![]); - for _ in 0..3 { - out = a.frame(vec![]); - } - let select = |a: &mut App, out: &egui::FullOutput| { - let r = text_rect(out, length); - let (from, to) = (r.left_center() + vec2(1.0, 0.0), r.right_center() - vec2(1.0, 0.0)); - a.frame(vec![Event::PointerMoved(from)]); - a.frame(vec![click(from, true)]); - for k in 1..=4 { - a.frame(vec![Event::PointerMoved(from + (to - from) * k as f32 / 4.0)]); - } - a.frame(vec![click(to, false)]); - a.frame(vec![]) - }; - // Cmd+C or Cmd+X: the chord's frame, then the frame after it, when the keys are let go. - let chord = |a: &mut App, e: Event| { - let out = a.frame(vec![Event::ModifiersChanged(Modifiers::COMMAND), e]); - (out, a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)])) - }; + let select = |a: &mut App, out: &egui::FullOutput| select_label_text(a, out, length); + let chord = clipboard_chord; let out = select(&mut a, &out); let (copy, after) = chord(&mut a, Event::Copy); assert_eq!(copied(©), [length], "Copy copies the selected value"); @@ -313,20 +327,45 @@ fn copy_and_cut_copy_the_text_selected_in_a_panel_label() { assert!(copied(&after).is_empty(), "and nothing after it"); assert_eq!(a.selected(), 1, "and leaves the art"); assert!(a.app.session.clipboard.is_empty(), "no art cut"); + // Cut on a chord of the user's own that no other command has, which egui also sends as Cut: the + // keymap does not cut the art after the label. + let overrides = a.app.ui.shortcut_overrides.clone(); + crate::keymap::set_override(&mut a.app.ui.shortcut_overrides, "edit.cut", "Cmd+Alt+Shift+X"); + let cut = a.frame(vec![Event::ModifiersChanged(Modifiers::COMMAND | Modifiers::ALT | Modifiers::SHIFT), Event::Cut]); + a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)]); + assert_eq!(copied(&cut), [length], "Cut on the user's chord copies the selected value"); + assert_eq!(a.selected(), 1, "and leaves the art"); + assert!(a.app.session.clipboard.is_empty(), "no art cut"); + a.app.ui.shortcut_overrides = overrides; // The menu bar's Edit › Copy (macOS). let menu = a.menu("edit.copy"); a.frame(vec![]); assert_eq!(copied(&menu), [length], "the menu's Copy copies the selected value"); assert!(a.app.session.clipboard.is_empty(), "no art copied"); + // The same in a frame that also runs a Copy another window sent on. + (a.app.forwarded_frame, a.app.forwarded_clipboard) = (true, true); + let menu = a.menu("edit.copy"); + (a.app.forwarded_frame, a.app.forwarded_clipboard) = (false, false); + a.frame(vec![]); + assert_eq!(copied(&menu), [length], "the menu's Copy copies the selected value with a Copy sent on"); + assert!(a.app.session.clipboard.is_empty(), "no art copied"); + // Cmd+C in a frame that also runs other keys another window sent on (a key let go there). + a.app.forwarded_frame = true; + let copy = a.frame(vec![Event::ModifiersChanged(Modifiers::COMMAND), Event::Copy]); + a.app.forwarded_frame = false; + a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)]); + assert_eq!(copied(©), [length], "Cmd+C copies the selected value with other keys sent on"); + assert!(a.app.session.clipboard.is_empty(), "no art copied"); // A Copy another window sends on: a floating panel's window whose label copied its text copies // nothing more. From any other window (a floating document's), the art is copied, not the text // still selected in this window's panel. let forward = |a: &mut App| { crate::panel_docking::forward_keys(&mut a.app, &a.ctx, vec![Event::Copy], Some(Modifiers::COMMAND)); a.app.forwarded_frame = !a.app.forwarded.is_empty(); + a.app.forwarded_clipboard = a.app.forwarded_frame; let events = std::iter::once(Event::ModifiersChanged(Modifiers::COMMAND)).chain(std::mem::take(&mut a.app.forwarded)).collect(); let out = a.frame(events); - a.app.forwarded_frame = false; + (a.app.forwarded_frame, a.app.forwarded_clipboard) = (false, false); (out, a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)])) }; crate::shortcuts::note_copied_in_window(&a.ctx); @@ -336,14 +375,48 @@ fn copy_and_cut_copy_the_text_selected_in_a_panel_label() { let (copy, _) = forward(&mut a); assert!(copied(©).iter().all(|t| t != length), "{length} was copied from the other window"); assert!(!a.app.session.clipboard.is_empty(), "Copy from the other window copied the art"); - // Tab hides the panels: the selected value is not drawn, so Copy copies the art, a frame later. + // Tab hides the panels: the selected value is not drawn, so Copy copies the art, a frame later, + // even when the window has lost the keyboard by then. select(&mut a, &out); a.app.ui.dock = false; - let (copy, after) = chord(&mut a, Event::Copy); + let copy = a.frame(vec![Event::ModifiersChanged(Modifiers::COMMAND), Event::Copy]); + a.focused = false; + let after = a.frame(vec![Event::ModifiersChanged(Modifiers::NONE)]); + a.focused = true; assert!(copied(©).is_empty(), "no label copied {length}"); assert!(copied(&after).iter().any(|t| t.starts_with(" Pos2 { diff --git a/crates/ui-egui/src/tests/sysclip.rs b/crates/ui-egui/src/tests/sysclip.rs index e5e83027d4..aac62b4039 100644 --- a/crates/ui-egui/src/tests/sysclip.rs +++ b/crates/ui-egui/src/tests/sysclip.rs @@ -164,6 +164,11 @@ pub(super) fn copy_rect(app: &mut VectorcraftApp) { run(app, "edit.copy", json!({})); } +/// How many times the app wrote the clipboard. +pub(super) fn writes(board: &Rc>) -> usize { + board.borrow().writes +} + pub(super) fn written(board: &Rc>) -> Vec<&'static str> { board.borrow().flavours.iter().map(|f| f.mime).collect() } diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef83de54ad..ebc81dcac4 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1158,6 +1158,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - On Windows and Linux, F2, F3 and F4 run Cut, Copy and Paste alongside Ctrl+X, Ctrl+C and Ctrl+V, and in the web build they do so everywhere except macOS. The Edit menu keeps the Ctrl shortcuts, and Keyboard Shortcuts lists both keys of each row. On macOS only Cmd+X, Cmd+C and Cmd+V are the defaults. F2, F3 and F4 do not run these commands in a focused text field or while the Type tool edits text. A saved shortcut set that assigns one of these keys to another command keeps that assignment. Public reference: [Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html). - 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). Not yet: Select All across threaded frames (one frame's text is selected). - 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 text selected in a panel's label, such as a Document Info value, Cmd/Ctrl+C and Cmd/Ctrl+X copy that text and do not copy or cut the art, and so do the menu bar's Copy and Cut on macOS. When the selected label is not drawn (the panels are hidden), the art is copied instead (#8432; VectorCraft's own behavior; `selectall::copy_and_cut_copy_the_text_selected_in_a_panel_label`). Not yet: the in-window Edit menu's Copy and Cut (the click on the menu clears the label's selection first), and the menu bar's Copy and Cut while the selected text is in a floating panel's own window (they copy the art). - 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, locked and hidden frames included, 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`, `textedit::convert_to_text_of_the_whole_story_converts_locked_and_hidden_frames`, `textedit::remove_breaks_of_the_whole_story_takes_locked_and_hidden_frames`). - When only some frames of a threaded story are selected, Remove Line Breaks and Remove Paragraph Breaks go through that story's frames once for all of them, not once per selected frame; each selected frame still loses its own breaks, in the order selected, as one undo step (`addons::cleanup::text::tests::remove_breaks_goes_through_a_partly_named_story_once`). - With the whole story of threaded text selected by Select All, the Character, Paragraph, OpenType, Tabs and Text Styles panels, the Justification dialog and the font menu change the frames that are in the edited frame's thread at the time of the change, locked and hidden frames included. A frame that has left the thread is not changed, and a frame added to the thread is (VectorCraft's own behavior; `panels::character::tests::story_changes_follow_the_edited_frames_thread_after_the_first_saved_frame_leaves`, `story_changes_leave_out_a_frame_that_left_and_take_in_a_frame_that_joined`, `story_changes_stay_in_the_edited_frame_once_its_thread_is_removed`, `story_changes_take_in_locked_and_hidden_frames`, `panels::tabs::tests::indent_markers_after_select_all_keep_each_story_paragraphs_indents`, `dialogs::justification::tests::justification_dialog_follows_the_story_thread_at_ok`).