From a0da3faffebafc0772b5a1902d66fd55b60501e6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 30 Oct 2026 10:10:21 -0700 Subject: [PATCH] Swatches: a Shift-click after switching documents starts a new range The panel cleared its swatch selection when the active document or the selected art changed, but kept the Shift-click range anchor. A Shift-click in the other document then selected every swatch from a name clicked in the first document (for example White) to the clicked one. The anchor is now cleared with the selection, so the Shift-click selects only the clicked swatch. --- crates/ui-egui/src/panels/swatches/body.rs | 1 + crates/ui-egui/src/panels/swatches/tests.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/crates/ui-egui/src/panels/swatches/body.rs b/crates/ui-egui/src/panels/swatches/body.rs index 9147960ba..611b12d6d 100644 --- a/crates/ui-egui/src/panels/swatches/body.rs +++ b/crates/ui-egui/src/panels/swatches/body.rs @@ -159,6 +159,7 @@ pub(super) fn focus_swatch(app: &VectorcraftApp, ui: &Ui, active: Option<&str>) let reselected = last_art.as_ref().is_some_and(|l| *l != art); if reselected { set_pstate(ui.ctx(), "swatch-selected", Vec::::new()); + set_pstate(ui.ctx(), "swatch-anchor", String::new()); } let changed = reselected || last_art.is_none() || last_swatch.as_deref() != active; set_pstate(ui.ctx(), "swatch-focus", (Some(art), active.map(str::to_string))); diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index 7d751fe9d..c65941370 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -133,6 +133,21 @@ fn modifier_clicks_select_several_swatches_and_groups() { assert_eq!(selected(&ctx), ["Grays"], "a plain click on a group selects it alone"); } +#[test] +fn switching_documents_clears_the_swatch_range_anchor() { + let mut app = app(); + let ctx = context(); + click_tile(&mut app, &ctx, "White", Modifiers::NONE, 0.0); + assert_eq!(selected(&ctx), ["White"]); + + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + frame(&mut app, &ctx, vec![], 1.0, show); + assert!(selected(&ctx).is_empty()); + + click_tile(&mut app, &ctx, "Black", Modifiers::SHIFT, 2.0); + assert_eq!(selected(&ctx), ["Black"]); +} + /// A color swatch or a recent color clicked in the panel becomes the Color Guide's base color /// (#3137); a modifier click only selects. #[test]