From 20791a7314ff6b82d9a3337923dd3cf2e46199be Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 18 Nov 2026 15:03:14 -0800 Subject: [PATCH] Keep sampler lifecycle conditions in focused helpers --- crates/ui-egui/src/canvas.rs | 18 +++++++++++------- crates/ui-egui/src/panels/image_trace.rs | 12 ++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 11f681cb39..3aa4c262fc 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -264,13 +264,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { app.ui.home = None; } let home_showing = crate::menus::home_showing(app); - if home_showing || app.session.active().is_none() { - // Home and the empty window still advance egui's click history. Observe the same - // correction there so it retires after the two ordinary clicks that replace a pick. - let id = egui::Id::unique("canvas"); - begin_ignore_sampler_pointer(ui, id, false); - end_ignore_sampler_pointer(ui, id); - } + observe_hidden_ignore_sampler_pointer(app, ui, home_showing); if home_showing { // No IME owner this pass (`ime_caret_rect` stays None): the end-of-pass observation marks // the context absent and keeps any marked text as typed. @@ -577,6 +571,16 @@ fn end_ignore_sampler_pointer(ui: &Ui, id: egui::Id) { } } +fn observe_hidden_ignore_sampler_pointer(app: &VectorcraftApp, ui: &Ui, home_showing: bool) { + if home_showing || app.session.active().is_none() { + // Home and the empty window still advance egui's click history. Observe the same + // correction there so it retires after the two ordinary clicks that replace a pick. + let id = egui::Id::unique("canvas"); + begin_ignore_sampler_pointer(ui, id, false); + end_ignore_sampler_pointer(ui, id); + } +} + /// A sampler press keeps its release, even if its Down completes or its binding expires held. fn input_after_sampler_refresh(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect: egui::Rect, cancelled: bool) { let consumed = begin_ignore_sampler_pointer(ui, resp.id, cancelled); diff --git a/crates/ui-egui/src/panels/image_trace.rs b/crates/ui-egui/src/panels/image_trace.rs index 04000ee0d4..0303467c3c 100644 --- a/crates/ui-egui/src/panels/image_trace.rs +++ b/crates/ui-egui/src/panels/image_trace.rs @@ -316,6 +316,13 @@ pub(crate) fn cancel_ignore_sampler(app: &mut VectorcraftApp, restore: bool) { } } +/// Presets and restored panel settings can turn Ignore Color off without its checkbox. +fn cancel_disabled_ignore_sampler(app: &mut VectorcraftApp, params: &Value) { + if params["ignoreWhite"] != true { + cancel_ignore_sampler(app, true); + } +} + /// Also runs when the panel is closed: document changes and tool changes end the pick. pub(crate) fn refresh_ignore_sampler(app: &mut VectorcraftApp) -> bool { let Some(s) = app.ui.trace_ignore_sampler.as_ref() else { return false }; @@ -1070,10 +1077,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if is_trace || !preview { st.preview_off = !preview; } - // Presets and restored panel settings can turn Ignore Color off without its checkbox. - if st.params["ignoreWhite"] != true { - cancel_ignore_sampler(app, true); - } + cancel_disabled_ignore_sampler(app, &st.params); if retrace && is_trace && preview { trace(app, ui.ctx(), &mut st); }