From e9b593f2ea62425e3e9407852592ce9b0cb1d45f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 16:58:43 -0800 Subject: [PATCH 1/2] Document Info: a click on a value copies it A click on a Document Info value copies the whole value to the clipboard and the status bar shows "Copied the value". Dragging across a value still selects part of it, a Shift-click still extends the selection, and a double click copies the value once and selects a word. Part of #8432. --- crates/ui-egui/src/panels/doc_info.rs | 29 ++++++++++++++++++---- crates/ui-egui/src/tests/selectall.rs | 35 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/doc_info.rs b/crates/ui-egui/src/panels/doc_info.rs index 88ee1d6f6f..7f85921deb 100644 --- a/crates/ui-egui/src/panels/doc_info.rs +++ b/crates/ui-egui/src/panels/doc_info.rs @@ -31,13 +31,25 @@ pub struct DocInfoView { } /// A `label: value` row. `label` is shown as given: translate an interface label first, a name -/// stays as it is. -pub(crate) fn row(ui: &mut Ui, label: &str, value: String) { +/// stays as it is. Whether the value was clicked to copy it: a click with no key held, other than +/// the second or third click of a double or triple click. +pub(crate) fn row(ui: &mut Ui, label: &str, value: &str) -> bool { + let mut clicked = false; Row::new().fill_width().align(RowAlign::SpaceBetween).wrap(true).show(ui, |ui, _| { Text::new(label.to_string()).shade(Shade::Muted).show(ui); - // The value can be selected and copied (#8432). - SelectableText::new(label.to_string(), &value).show(ui); + // The value can be selected and copied, and a click copies all of it (#8432). A drag selects + // and a Shift-click extends the selection, so neither copies. + let shown = SelectableText::new(label.to_string(), value).show(ui); + clicked = shown.contains_pointer() + && ui.input(|i| { + let primary = egui::PointerButton::Primary; + i.pointer.button_clicked(primary) + && !i.pointer.button_double_clicked(primary) + && !i.pointer.button_triple_clicked(primary) + && i.modifiers.is_none() + }); }); + clicked } /// `document.info` with its categories, fetched again only when the document, the scope or the @@ -64,6 +76,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { return; }; let DocInfoView { selection_only: sel_only, category } = app.ui.doc_info.clone(); + let mut copy = None; Stack::new().show(ui, |ui, _| { let sections = i["sections"].as_array().map_or(&[][..], Vec::as_slice); let shown = sections.iter().filter(|s| category.is_empty() || s["id"] == category.as_str()); @@ -92,11 +105,17 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { Text::new(super::label_or_name(label, !named.contains(&k)).to_string()).shade(Shade::Muted).show(ui); } else { let shown = shown_value(&i, id, k, (label, value), named.contains(&k)).unwrap_or_else(|| value.to_string()); - row(ui, super::label_or_name(label, !named.contains(&k)), shown); + if row(ui, super::label_or_name(label, !named.contains(&k)), &shown) { + copy = Some(shown); + } } } } }); + if let Some(text) = copy { + app.clipboard_out = Some(text); + app.status("Copied the value"); + } } /// A Brushes row's value in the interface language: the brush's type (`Art Brush`), or that the diff --git a/crates/ui-egui/src/tests/selectall.rs b/crates/ui-egui/src/tests/selectall.rs index 9c20603db8..386fe9d14b 100644 --- a/crates/ui-egui/src/tests/selectall.rs +++ b/crates/ui-egui/src/tests/selectall.rs @@ -380,6 +380,41 @@ fn copy_and_cut_copy_the_text_selected_in_a_panel_label() { assert!(copied(&after).iter().any(|t| t.starts_with(">| frames.into_iter().flat_map(|events| copied(&a.frame(events))).collect::>(); + let (status, sets) = (a.app.ui.status.clone(), a.app.ui.status_sets); + let clicked = copies(&mut a, vec![vec![Event::PointerMoved(at)], vec![click(at, true)], vec![click(at, false)], vec![]]); + assert_eq!(clicked, [length], "a click copies the value, once"); + assert!(a.app.ui.status_sets != sets && a.app.ui.status != status, "the status bar says it was copied"); + assert_eq!(a.selected(), 1, "the art stays selected"); + assert!(a.app.session.clipboard.is_empty(), "no art copied"); + a.time += 1.0; + let twice = copies(&mut a, vec![vec![click(at, true)], vec![click(at, false)], vec![click(at, true)], vec![click(at, false)], vec![]]); + assert_eq!(twice, [length], "a double click copies the value once"); + a.time += 1.0; + let (from, to) = (text_rect(&out, length).left_center() + vec2(1.0, 0.0), text_rect(&out, length).right_center() - vec2(1.0, 0.0)); + let mut drag = vec![vec![Event::PointerMoved(from)], vec![click(from, true)]]; + drag.extend((1..=4).map(|k| vec![Event::PointerMoved(from + (to - from) * k as f32 / 4.0)])); + drag.extend([vec![click(to, false)], vec![]]); + assert!(copies(&mut a, drag).is_empty(), "a drag selects and copies nothing"); + a.time += 1.0; + let shift = Event::ModifiersChanged(Modifiers::SHIFT); + let extended = copies( + &mut a, + vec![vec![shift, Event::PointerMoved(at)], vec![click(at, true)], vec![click(at, false)], vec![Event::ModifiersChanged(Modifiers::NONE)]], + ); + assert!(extended.is_empty(), "a Shift-click copies nothing"); +} + /// Drag across a label in a window of its own (a floating panel's), selecting its text there. The /// main window's labels then copy nothing on Copy or Cut, which run on the art a pass later. fn select_label_text_in_another_window(a: &mut App) { From a0cbd24102065e0e86db587da731dcaab29897ad Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 21:46:03 -0800 Subject: [PATCH 2/2] Document Info: copy the value the click was released on The click copies the value under the release event's position, and a Shift-click copies nothing even when the key release arrives in the same frame. --- crates/ui-egui/src/panels/doc_info.rs | 21 +++++++++----- crates/ui-egui/src/tests/selectall.rs | 42 +++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/panels/doc_info.rs b/crates/ui-egui/src/panels/doc_info.rs index 7f85921deb..87eb9f9880 100644 --- a/crates/ui-egui/src/panels/doc_info.rs +++ b/crates/ui-egui/src/panels/doc_info.rs @@ -40,14 +40,21 @@ pub(crate) fn row(ui: &mut Ui, label: &str, value: &str) -> bool { // The value can be selected and copied, and a click copies all of it (#8432). A drag selects // and a Shift-click extends the selection, so neither copies. let shown = SelectableText::new(label.to_string(), value).show(ui); - clicked = shown.contains_pointer() - && ui.input(|i| { - let primary = egui::PointerButton::Primary; - i.pointer.button_clicked(primary) - && !i.pointer.button_double_clicked(primary) - && !i.pointer.button_triple_clicked(primary) - && i.modifiers.is_none() + // The click's own position and keys: a move or a key change after the release in the same + // frame leaves the pointer and the held keys elsewhere. A frame with more than one release + // copies nothing, since the click flags below do not say which release they describe. + let area = shown.interact_rect.intersect(ui.clip_rect()); + let primary = egui::PointerButton::Primary; + let release = ui.input(|i| { + let mut releases = i.events.iter().filter_map(|e| match e { + egui::Event::PointerButton { pos, button, pressed: false, modifiers } if *button == primary => Some((*pos, *modifiers)), + _ => None, }); + let release = releases.next().filter(|_| releases.next().is_none()); + let single = i.pointer.button_clicked(primary) && !i.pointer.button_double_clicked(primary) && !i.pointer.button_triple_clicked(primary); + release.filter(|_| single) + }); + clicked = release.is_some_and(|(pos, keys)| keys.is_none() && area.contains(pos) && ui.ctx().layer_id_at(pos) == Some(ui.layer_id())); }); clicked } diff --git a/crates/ui-egui/src/tests/selectall.rs b/crates/ui-egui/src/tests/selectall.rs index 386fe9d14b..ed97ffcdb7 100644 --- a/crates/ui-egui/src/tests/selectall.rs +++ b/crates/ui-egui/src/tests/selectall.rs @@ -382,7 +382,8 @@ fn copy_and_cut_copy_the_text_selected_in_a_panel_label() { /// #8432: a click on a Document Info value copies the whole value and says so in the status bar, and /// leaves the art. A double click copies it once, and a drag across the value or a Shift-click on -/// it copies nothing. +/// it copies nothing. The click's own position and keys count, not where the pointer and the keys +/// are at the end of its frame. #[test] fn a_click_on_a_document_info_value_copies_it() { let mut a = App::new(); @@ -408,11 +409,48 @@ fn a_click_on_a_document_info_value_copies_it() { assert!(copies(&mut a, drag).is_empty(), "a drag selects and copies nothing"); a.time += 1.0; let shift = Event::ModifiersChanged(Modifiers::SHIFT); + let shift_click = + |at: Pos2, pressed: bool| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::SHIFT }; let extended = copies( &mut a, - vec![vec![shift, Event::PointerMoved(at)], vec![click(at, true)], vec![click(at, false)], vec![Event::ModifiersChanged(Modifiers::NONE)]], + vec![ + vec![shift.clone(), Event::PointerMoved(at)], + vec![shift_click(at, true)], + vec![shift_click(at, false)], + vec![Event::ModifiersChanged(Modifiers::NONE)], + ], ); assert!(extended.is_empty(), "a Shift-click copies nothing"); + a.time += 1.0; + // Shift let go in the frame of the release: the click was still a Shift-click. + let let_go = copies( + &mut a, + vec![ + vec![shift, Event::PointerMoved(at)], + vec![shift_click(at, true)], + vec![shift_click(at, false), Event::ModifiersChanged(Modifiers::NONE)], + vec![], + ], + ); + assert!(let_go.is_empty(), "a Shift-click copies nothing when Shift is let go in the same frame"); + a.time += 1.0; + // Released on the length, then moved onto the Paths count in the same frame. + let there = text_rect(&out, "2").center(); + let moved = + copies(&mut a, vec![vec![Event::PointerMoved(at)], vec![click(at, true)], vec![click(at, false), Event::PointerMoved(there)], vec![]]); + assert_eq!(moved, [length], "a click copies the value it was released on, not the one the pointer moved to"); + a.time += 1.0; + // A click on the Paths count, then a drag across the length, in one frame. + let (from, to) = (text_rect(&out, length).left_center() + vec2(1.0, 0.0), text_rect(&out, length).right_center() - vec2(1.0, 0.0)); + let both = copies( + &mut a, + vec![ + vec![Event::PointerMoved(there)], + vec![click(there, true), click(there, false), Event::PointerMoved(from), click(from, true), Event::PointerMoved(to), click(to, false)], + vec![], + ], + ); + assert!(!both.iter().any(|t| t == length), "a drag after a click in the same frame does not copy the dragged value"); } /// Drag across a label in a window of its own (a floating panel's), selecting its text there. The