From e9b593f2ea62425e3e9407852592ce9b0cb1d45f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 16:58:43 -0800 Subject: [PATCH] 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) {