From 22cacbf198682c1fce6421d5ffd15476ff4b7ec9 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 17 Oct 2026 19:21:38 +0200 Subject: [PATCH] Perspective Crop: switching documents drops the pending box (#7130) perspective_crop_ui::cancel_stale ran only on a pointer event or a commit, so after a tab switch the other document's quad was drawn (and reported) until the next press. sync_views now runs it next to the Crop tool's cancel_stale. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/perspective_crop_ui.rs | 28 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 04c37282e6..e3a3e2a99e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1232,6 +1232,7 @@ impl PhotocraftApp { // ... and to the document it was started on. crate::canvas::polygon_cancel_stale(self); crate::crop_ui::cancel_stale(self); + crate::perspective_crop_ui::cancel_stale(self); let ids: Vec = self.session.documents().iter().map(|d| d.doc.id).collect(); // Where the document of view `i` is now. Views not tracked yet keep their index. let now = |i: usize| match self.view_docs.get(i) { diff --git a/crates/ui-egui/src/perspective_crop_ui.rs b/crates/ui-egui/src/perspective_crop_ui.rs index c44b54dc4a..6c181e49de 100644 --- a/crates/ui-egui/src/perspective_crop_ui.rs +++ b/crates/ui-egui/src/perspective_crop_ui.rs @@ -59,8 +59,9 @@ pub fn cancel(app: &mut PhotocraftApp) { app.pcrop.clicks.clear(); } -/// Another document became active: its pending quad is dropped. -fn cancel_stale(app: &mut PhotocraftApp) { +/// Another document became active: its pending quad is dropped (also from `sync_views`, so it is +/// never drawn on the other document). +pub(crate) fn cancel_stale(app: &mut PhotocraftApp) { let doc = app.session.active().map(|st| st.doc.id); if pending(app) && app.pcrop.doc.is_some() && app.pcrop.doc != doc { cancel(app); @@ -323,4 +324,27 @@ mod tests { assert_eq!(ordered([[10.0, 90.0], [100.0, 5.0], [0.0, 0.0], [90.0, 100.0]]), [[0.0, 0.0], [100.0, 5.0], [90.0, 100.0], [10.0, 90.0]]); } + + /// The pending quad belongs to its document (#1918): switching documents drops it, so it is + /// never drawn on the other one; on its own document it stays. + #[test] + fn switching_documents_drops_the_pending_quad() { + let mut s = photocraft_engine::Session::new(); + for name in ["a", "b"] { + s.add_document(Document::with_background(name, Size::new(200, 150), ColorMode::Rgb, SampleType::U8, Color::WHITE), None); + } + s.set_active(0); + let mut app = PhotocraftApp::new(s, crate::Services::default()); + app.ui.tool = Tool::PerspectiveCrop; + let ev = |app: &mut PhotocraftApp, e| assert!(pointer(app, e)); + ev(&mut app, ToolEvent::Down { x: 20.0, y: 10.0, pressure: 1.0 }); + ev(&mut app, ToolEvent::Move { x: 120.0, y: 90.0, pressure: 1.0 }); + ev(&mut app, ToolEvent::Up { x: 120.0, y: 90.0 }); + app.sync_views(); + assert!(app.ui.perspective_crop.is_some(), "same document: the quad stays"); + app.session.set_active(1); + app.sync_views(); + assert_eq!(app.ui.perspective_crop, None); + assert!(app.pcrop.drag.is_none() && app.pcrop.clicks.is_empty()); + } }