mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 13:15:12 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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("<?xml")), "Copy copied the art");
|
||||
}
|
||||
|
||||
/// #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.
|
||||
#[test]
|
||||
fn a_click_on_a_document_info_value_copies_it() {
|
||||
let mut a = App::new();
|
||||
let out = show_document_info(&mut a);
|
||||
let length = "234 pt";
|
||||
let at = text_rect(&out, length).center();
|
||||
// Each step's frames, and what they copied.
|
||||
let copies = |a: &mut App, frames: Vec<Vec<Event>>| frames.into_iter().flat_map(|events| copied(&a.frame(events))).collect::<Vec<_>>();
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user