diff --git a/crates/ui-egui/src/panels/swatches/dnd.rs b/crates/ui-egui/src/panels/swatches/dnd.rs index 2c36dabcb3..9946b0749f 100644 --- a/crates/ui-egui/src/panels/swatches/dnd.rs +++ b/crates/ui-egui/src/panels/swatches/dnd.rs @@ -144,7 +144,10 @@ pub(super) fn tile_input(ui: &Ui, resp: Response, e: &Entry, items: &[Entry], se }), _ => resp.on_hover_text(shown), }; - if resp.clicked() { + // A double-click's first click already applied and selected the swatch; its second only opens + // the editor. Pattern editing selects the tile art, which the second click would paint with + // the pattern itself. + if resp.clicked() && !resp.double_clicked() { ev.clicked = Some((e.clone(), ui.input(|i| i.modifiers))); } } diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index 8e313e9d77..0b9bb1d8b3 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -518,6 +518,42 @@ fn list_view_rows_take_double_clicks_and_folder_clicks_select_the_group() { assert_eq!(describe(&Paint::solid(Color::gray(0.5)), true, true), "Spot Color, Grayscale"); } +/// A double-click on a pattern swatch, its clicks on frames of their own as a pointer makes them: +/// the first click paints the selected art with the pattern, and the second opens pattern editing +/// on that pattern without painting the tile art, which editing selects, with the pattern itself +/// (#7095). +#[test] +fn double_clicking_a_pattern_edits_it_without_painting_its_tile() { + let mut app = app(); + let tile = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap(); + app.run("object.pattern.make", json!({"ids": [tile], "name": "Dots", "width": 20, "height": 20})).unwrap(); + app.run("object.pattern.done", json!({})).unwrap(); + let art = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + for view in [View::SmallThumb, View::SmallList] { + app.ui.swatches_view = view; + let ctx = context(); + // Only the pattern shows, so its row is on screen in the list view too. + set_pstate(&ctx, "swatch-show-find", true); + ctx.data_mut(|d| d.insert_temp(find_id(), "Dots".to_string())); + frame(&mut app, &ctx, vec![], 0.0, show); + let at = tile_center(&ctx, "Dots"); + let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + for (i, e) in [Event::PointerMoved(at), button(true), button(false), button(true), button(false)].into_iter().enumerate() { + frame(&mut app, &ctx, vec![e], 1.0 + i as f64 * 0.05, show); + } + let d = &app.session.doc().unwrap().doc; + let pe = d.pattern_edit.as_ref().unwrap_or_else(|| panic!("{view:?}: the double-click opens pattern editing")); + assert_eq!(pe.pattern, "Dots"); + let fill = d.node(vectorcraft_doc::NodeId(art)).unwrap().appearance.fill_paint(); + assert!(matches!(fill, Paint::Pattern { pattern, .. } if pattern == "Dots"), "the first click paints the art"); + for n in d.node(pe.layer).unwrap().children().unwrap() { + assert!(!matches!(n.appearance.fill_paint(), Paint::Pattern { .. }), "{view:?}: the tile keeps its own fill: {}", app.ui.status); + } + app.run("object.pattern.done", json!({})).unwrap(); + app.run("select.set", json!({"ids": [art]})).unwrap(); + } +} + #[test] fn dragging_tiles_reorders_and_moves_into_groups_as_one_undo_step_each() { let mut app = app();