Fix #7095: a double-click on a pattern swatch no longer paints its tile

The second click of a double-click on a swatch also counted as a plain
click. After the double-click opened pattern editing, which selects the
tile art, that click applied the pattern swatch to the tile, so the
pattern held a copy of itself. The second click now only opens the
editor; the first click still applies and selects the swatch.

Reported by erolkarino. #7164 by mockydevs makes the engine refuse
painting the tile with its own pattern; this change stops the swatch
panel from sending that paint on a double-click.
This commit is contained in:
dotCooCoo
2026-11-17 06:54:13 -08:00
parent 0f8040ef59
commit 02da66521f
2 changed files with 40 additions and 1 deletions
+4 -1
View File
@@ -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)));
}
}
@@ -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();