From d487711f1927d82ff391321d27a260f60f869dc7 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:01:33 +0100 Subject: [PATCH 1/9] fix(ui): close canvas menu when the active document changes Reuse the existing document identity reset so Zoom In and Zoom Out cannot apply a point from the previous document. Same-document edits keep the menu. --- crates/ui-egui/src/app/commands.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 9a5621c5be..188a9426ae 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -291,9 +291,9 @@ impl PhotocraftApp { } pub fn sync_views(&mut self) { - // The Paths panel selection belongs to the active document. Ordinary edits replace the - // snapshot and advance its revision; a replaced snapshot without a newer revision is a - // reopened document, even with the same ID. + // The Paths panel selection and canvas context menu belong to the active document. + // Ordinary edits replace the snapshot and advance its revision; a replaced snapshot + // without a newer revision is a reopened document, even with the same ID. let document = self.session.active().map(|st| (st.doc.id, st.revision, std::sync::Arc::downgrade(&st.doc))); let same_document = match (&self.path_document, &document) { (Some((old_id, old_revision, old_source)), Some((id, revision, source))) => old_id == id && (revision > old_revision || old_source.ptr_eq(source)), @@ -302,6 +302,7 @@ impl PhotocraftApp { }; if !same_document { self.ui.selected_path = None; + self.ui.canvas_tool_menu = None; } self.path_document = document; vector_ui::cancel_stale_pen(self); From 20c7feb37bff6d40b0ebf55264f7cb11e0b3d7c4 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:02:01 +0100 Subject: [PATCH 2/9] test(ui): cover canvas menu document switching and tab closure Cover Zoom and Hand menus, ordinary edits in the owning document, replacement of the active slot, and an owning document that survives another tab closing. --- crates/ui-egui/src/view_sync_tests.rs | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/ui-egui/src/view_sync_tests.rs b/crates/ui-egui/src/view_sync_tests.rs index 0cae764e62..120715f0b3 100644 --- a/crates/ui-egui/src/view_sync_tests.rs +++ b/crates/ui-egui/src/view_sync_tests.rs @@ -44,3 +44,41 @@ fn every_document_keeps_its_own_view_through_syncs() { assert_eq!(app.ui.views[0].zoom, 3.2, "the first document's view is untouched"); assert_eq!(app.ui.views[1].zoom, 4.0, "the last document's view follows it to its new index"); } + +/// #11325: Zoom In/Out must never use a point right-clicked in another document. +#[test] +fn switching_documents_closes_the_canvas_view_menu() { + for tool in [crate::Tool::Zoom, crate::Tool::Hand] { + let mut app = app_with_two_documents(); + app.ui.tool = tool; + let ctx = egui::Context::default(); + assert!(crate::canvas_tool_menu::open_view(&mut app, &ctx, tool, [10.0, 10.0], [20.0, 20.0])); + app.sync_views(); + assert!(app.ui.canvas_tool_menu.is_some(), "ordinary sync keeps the menu"); + app.run("layer.new.layer", json!({})).unwrap(); + assert!(app.ui.canvas_tool_menu.is_some(), "an edit in the same document keeps the menu"); + assert!(app.session.set_active(0)); + app.sync_views(); + assert!(app.ui.canvas_tool_menu.is_none(), "a document switch closes the old document's menu"); + } +} + +/// A tab closing can put another document at the same index, or move the menu's own document +/// to another index. Follow its identity, not its slot. +#[test] +fn closing_a_tab_keeps_the_canvas_menu_only_for_its_own_document() { + for close_menu_document in [false, true] { + let mut app = app_with_two_documents(); + if close_menu_document { + assert!(app.session.set_active(0)); + app.sync_views(); + } + app.ui.tool = crate::Tool::Hand; + let document = app.session.active().unwrap().doc.id; + assert!(crate::canvas_tool_menu::open_view(&mut app, &egui::Context::default(), crate::Tool::Hand, [10.0, 10.0], [20.0, 20.0])); + app.run("file.close", json!({"document": 0})).unwrap(); + assert_eq!(app.session.active_index(), Some(0), "the survivor occupies the first slot"); + assert_eq!(app.session.active().unwrap().doc.id == document, !close_menu_document); + assert_eq!(app.ui.canvas_tool_menu.is_some(), !close_menu_document, "only a menu for the surviving document stays open"); + } +} From 91dcb83fa64e45ce2c9803bcc2a7eb15426c0b02 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:02:25 +0100 Subject: [PATCH 3/9] docs(ui): record canvas menu dismissal on document changes Updated the context-menu parity contract to reflect changes in canvas menus closing on active document changes. --- docs/context-menu-parity.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/context-menu-parity.md b/docs/context-menu-parity.md index 1ef971ef33..56004900e6 100644 --- a/docs/context-menu-parity.md +++ b/docs/context-menu-parity.md @@ -1,13 +1,13 @@ # Context-menu parity contract -> **Last reviewed:** 2026-10-18 · **Last updated:** 2026-10-21 · **Change:** minor (Crop tool menu on a pending crop, #6561; Zoom tool menu order, #6005; Type tool menu over committed type, #7324; earlier: Path Selection canvas menu, #1056; pasteboard row: the menu exists, #2462) · **Target:** Adobe Photoshop 2026 +> **Last reviewed:** 2026-10-18 · **Last updated:** 2026-11-04 · **Change:** minor (canvas menus close when the active document changes, #11325; Crop tool menu on a pending crop, #6561; Zoom tool menu order, #6005; Type tool menu over committed type, #7324; earlier: Path Selection canvas menu, #1056; pasteboard row: the menu exists, #2462) · **Target:** Adobe Photoshop 2026 Status: implementation contract, updated 2026-10-09. Scope: canvas, document tabs, and panels. “Right-click” means a secondary pointer click; macOS Control-click should also open the same menu where the platform sends a context-menu gesture. Photoshop changes a context menu with the active tool, selection, and panel item. Adobe documents that principle but does not publish a complete current menu catalog. **Documented** means an Adobe source explicitly names the gesture or action. **Inferred** means a PhotoCraft design target or an item known from a main menu whose presence in a Photoshop context menu still needs a current-product capture. Do not present inferred rows as exact Photoshop menus. [Adobe: panels and menus](https://helpx.adobe.com/photoshop/using/panels-menus.html), [Adobe: shortcuts and context menus](https://helpx.adobe.com/sa_en/photoshop/using/customizing-keyboard-shortcuts.html). ## Dispatch contract 1. Hit-test the target before opening: modal operation/handle, text selection, canvas content, panel row or icon, tab, then empty workspace. A generic canvas menu must not swallow a more specific target. -2. Snapshot the target and selection when the menu opens. A row in an existing multiselection acts on that set; a row outside it becomes the target before its command runs. Apply the same rule to layers, channels, paths, and presets. +2. Snapshot the target and selection when the menu opens. A row in an existing multiselection acts on that set; a row outside it becomes the target before its command runs. Apply the same rule to layers, channels, paths, and presets. Canvas menus close when the active document changes, including when a closed tab leaves another document in its slot (#11325); ordinary edits in the same document keep the menu open. 3. Resolve items from a pure menu model keyed by target kind, active tool, document state, platform, and active operation. The model supplies label, command id, params, enabled state, and reason. Every mutating item dispatches an engine command; view-only items may update shell state. An unavailable feature is disabled with a reason or omitted, never a clickable no-op. 4. Preserve primary-button tool behavior. Secondary click only opens a menu unless a right-button drag gesture or the user's explicit right-erase preference owns the gesture. A drag must not briefly open a menu, and opening a menu must never paint, transform, sample, or commit. 5. Anchor at the pointer and clamp to the viewport; support keyboard context-menu key/Shift+F10 where available, Escape/outside click, separators only between nonempty groups, checked/radio state, keyboard navigation, and screen-reader labels. @@ -100,6 +100,7 @@ Each slice needs pure model tests (including every item dispatching a known comm | Date | Change | Summary | |---|---|---| +| 2026-11-04 | minor | Canvas menus close on an active-document change, so Zoom In/Out cannot reuse another document's clicked point (#11325) | | 2026-10-21 | minor | Crop tool menu on a pending crop (#6561) | | 2026-10-20 | trivial | Zoom tool menu order (#6005) | | 2026-10-18 | minor | Type tool menu over committed type (#7324) | From ae57082612e342246105647550bbfd456bf58566 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:29:55 +0100 Subject: [PATCH 4/9] test(ui): expect sampler menus to close on document switches Capture the stale menu before file.new, assert immediate dismissal, and preserve the cross-document Delete safety assertion. --- crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs b/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs index e950d770f3..2bb0e270b6 100644 --- a/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs +++ b/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs @@ -135,11 +135,12 @@ fn delete_never_removes_another_sampler_after_the_list_changes_under_the_menu() // Another document with a sampler at the same index and spot: still not this menu's sampler. right_click(&mut app, &ctx, 180.0, 90.0); assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); + let menu = app.ui.canvas_tool_menu.clone().expect("the menu is open before switching documents"); app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + assert!(app.ui.canvas_tool_menu.is_none(), "switching documents closes the menu"); for (x, y) in [(20, 20), (180, 90)] { app.run("view.colorSamplers.add", json!({"x": x, "y": y})).unwrap(); } - let menu = app.ui.canvas_tool_menu.clone().expect("the menu is still open"); assert!(!crate::canvas_tool_menu::entry_enabled(&app, &menu, SAMPLER_DELETE), "another document's sampler"); } From 1ed0f5ad7f061d73ef0549d87c04c61c4500be80 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:50:44 +0100 Subject: [PATCH 5/9] test(ui): carry sampler menu regression to the current analysis module Pre-resolve the upstream analysis_ui to analysis move. Preserve the complete current main sampler tests and add the document-switch menu assertion. The matching sync_views fix is retained in the companion update. --- .../src/tools/analysis/sampler_menu_tests.rs | 77 ++++++ .../tools/analysis_ui/sampler_menu_tests.rs | 224 ------------------ 2 files changed, 77 insertions(+), 224 deletions(-) create mode 100644 crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs delete mode 100644 crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs diff --git a/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs b/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs new file mode 100644 index 0000000000..16c1bb2f03 --- /dev/null +++ b/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs @@ -0,0 +1,77 @@ +//! #11733: the Color Sampler's right-click menu cannot act on a sampler that is gone. + +use serde_json::json; + +use crate::canvas_tool_menu::SAMPLER_DELETE; +use crate::{PhotocraftApp, Tool}; + +/// A 200 x 100 document with the Color Sampler and samplers at (20, 20) and (120, 60). +fn app() -> (Box, egui::Context) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.run("view.colorSamplers.add", json!({"x": 20, "y": 20})).unwrap(); + app.run("view.colorSamplers.add", json!({"x": 120, "y": 60})).unwrap(); + app.ui.tool = Tool::ColorSampler; + let ctx = app.ctx().clone(); + (app, ctx) +} + +/// A right-click at document point (x, y) through the window host, as a mouse sends it. +fn right_click(app: &mut PhotocraftApp, x: f64, y: f64) { + crate::canvas::testing::secondary_click(app, [x, y], egui::Modifiers::NONE); +} + +fn samplers(app: &PhotocraftApp) -> Vec<[f64; 2]> { + app.session.active().unwrap().color_samplers.clone() +} + +/// Delete never removes a different sampler when the list changes while the menu is open: one +/// deleted meanwhile, or another document with a sampler at the same index and spot. +#[test] +fn delete_never_removes_another_sampler_after_the_list_changes_under_the_menu() { + let (mut app, ctx) = app(); + app.run("view.colorSamplers.add", json!({"x": 180, "y": 90})).unwrap(); + right_click(&mut app, 120.0, 60.0); + assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); + // An agent deletes #1 while the menu is open: index 1 now names the old #3. + app.run("view.colorSamplers.delete", json!({"index": 0})).unwrap(); + crate::canvas_tool_menu::close_stale(&mut app); + assert!(app.ui.canvas_tool_menu.is_none(), "the menu's sampler moved, so the menu closes"); + crate::canvas_tool_menu::choose(&mut app, &ctx, SAMPLER_DELETE); + assert_eq!(samplers(&app), [[120.5, 60.5], [180.5, 90.5]], "no other sampler is deleted"); + + // Another document with a sampler at the same index and spot: still not this menu's sampler. + right_click(&mut app, 180.0, 90.0); + assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + assert!(app.ui.canvas_tool_menu.is_none(), "switching documents closes the menu"); + for (x, y) in [(20, 20), (180, 90)] { + app.run("view.colorSamplers.add", json!({"x": x, "y": y})).unwrap(); + } + crate::canvas_tool_menu::close_stale(&mut app); + crate::canvas_tool_menu::choose(&mut app, &ctx, SAMPLER_DELETE); + assert_eq!(samplers(&app).len(), 2, "another document's sampler is not deleted"); +} + +/// A stale index, a non-finite point, or no document at all: `sampler_at` answers `None`, and a +/// Delete then changes nothing and never panics. +#[test] +fn a_stale_sampler_or_odd_point_fails_gracefully() { + let (mut app, ctx) = app(); + app.run("view.colorSamplers.clear", json!({})).unwrap(); + app.run("view.colorSamplers.add", json!({"x": 5, "y": 5})).unwrap(); + assert_eq!(super::sampler_at(&app, [120.0, 60.0]), None, "the sampler at that spot is gone"); + for p in [[f64::NAN, 5.0], [f64::INFINITY, 5.0], [5.0, f64::NEG_INFINITY]] { + assert_eq!(super::sampler_at(&app, p), None, "{p:?}"); + } + crate::canvas_tool_menu::choose(&mut app, &ctx, SAMPLER_DELETE); + assert_eq!(samplers(&app), [[5.5, 5.5]], "Delete with no open menu removes nothing"); + + let mut empty = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + empty.ui.tool = Tool::ColorSampler; + assert_eq!(super::sampler_at(&empty, [1.0, 1.0]), None); + if crate::canvas_tool_menu::open_at(&mut empty, Tool::ColorSampler, Default::default(), egui::pos2(10.0, 10.0), [1.0, 1.0], None) { + crate::canvas_tool_menu::choose(&mut empty, &ctx, SAMPLER_DELETE); + } + assert!(empty.session.active().is_none()); +} diff --git a/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs b/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs deleted file mode 100644 index 2bb0e270b6..0000000000 --- a/crates/ui-egui/src/tools/analysis_ui/sampler_menu_tests.rs +++ /dev/null @@ -1,224 +0,0 @@ -//! #11733: the Color Sampler's right-click menu on the canvas. - -use egui::{Event, Modifiers, PointerButton, vec2}; -use egui_kittest::Harness; -use serde_json::{Value, json}; - -use crate::canvas_tool_menu::{SAMPLER_DELETE, SAMPLER_MENU}; -use crate::control::{ControlRequest, Outcome, handle}; -use crate::{PhotocraftApp, Tool}; - -/// A 200 x 100 document with the Color Sampler and samplers at (20, 20) and (120, 60). -fn app() -> (PhotocraftApp, egui::Context) { - let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); - app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); - app.run("view.colorSamplers.add", json!({"x": 20, "y": 20})).unwrap(); - app.run("view.colorSamplers.add", json!({"x": 120, "y": 60})).unwrap(); - app.ui.tool = Tool::ColorSampler; - (app, egui::Context::default()) -} - -fn control(app: &mut PhotocraftApp, ctx: &egui::Context, method: &str, params: Value) -> Value { - let (req, _rx) = ControlRequest::new(method, params); - let Outcome::Done(v) = handle(app, ctx, &req) else { panic!("{method} replies at once") }; - v -} - -/// An agent's right-click at document point (x, y), as `ui.pointer` sends it. -fn right_click(app: &mut PhotocraftApp, ctx: &egui::Context, x: f64, y: f64) { - let r = control(app, ctx, "ui.pointer", json!({"button": "secondary", "events": [{"kind": "down", "x": x, "y": y}, {"kind": "up", "x": x, "y": y}]})); - assert_eq!(r["ok"], json!(true), "{r}"); -} - -fn entries(app: &mut PhotocraftApp, ctx: &egui::Context) -> Vec { - let r = control(app, ctx, "ui.inspect", json!({})); - r["result"]["canvasToolMenu"]["entries"].as_array().cloned().unwrap_or_else(|| panic!("no canvasToolMenu: {r}")) -} - -fn samplers(app: &PhotocraftApp) -> Vec<[f64; 2]> { - app.session.active().unwrap().color_samplers.clone() -} - -/// The reference application's rows, in order, with `|` for a separator. -const EXPECTED: &[&str] = &[ - "Delete", - "|", - "Actual Color", - "Proof Color", - "|", - "Grayscale", - "RGB Color", - "Web Color", - "HSB Color", - "HSL Color", - "CMYK Color", - "Lab Color", - "|", - "Grayscale 16 bit", - "RGB 16 bit", - "CMYK 16 bit", - "Lab 16 bit", - "|", - "Total Ink", -]; - -fn labels(entries: &[Value]) -> Vec { - entries.iter().map(|e| if e["separator"] == json!(true) { "|".to_string() } else { e["label"].as_str().unwrap().to_string() }).collect() -} - -#[test] -fn right_click_on_a_sampler_lists_the_menu_in_order_with_delete_enabled() { - let (mut app, ctx) = app(); - right_click(&mut app, &ctx, 20.5, 20.5); - let menu = app.ui.canvas_tool_menu.clone().expect("the Color Sampler menu opens"); - assert_eq!(menu.tool, Tool::ColorSampler); - assert_eq!(menu.sampler, Some(0)); - let entries = entries(&mut app, &ctx); - assert_eq!(labels(&entries), EXPECTED); - let enabled: Vec<&str> = entries.iter().filter(|e| e["enabled"] == json!(true)).filter_map(|e| e["id"].as_str()).collect(); - // The readout rows wait for per-sampler readout modes (#11735) and stay greyed until then. - assert_eq!(enabled, [SAMPLER_DELETE]); - for (_, id) in SAMPLER_MENU.iter().flatten() { - assert!(!crate::canvas_tool_menu::mode_checked(&app, &menu, id), "{id} shows no checkmark"); - } - assert_eq!(samplers(&app).len(), 2, "the right-click places no sampler"); -} - -#[test] -fn right_click_off_a_sampler_greys_every_row() { - let (mut app, ctx) = app(); - right_click(&mut app, &ctx, 70.0, 40.0); - let menu = app.ui.canvas_tool_menu.clone().expect("the menu opens off a sampler too"); - assert_eq!(menu.sampler, None); - let entries = entries(&mut app, &ctx); - assert_eq!(labels(&entries), EXPECTED); - assert!(entries.iter().all(|e| e["enabled"] != json!(true)), "every row greyed: {entries:?}"); - let r = control(&mut app, &ctx, "ui.context.choose", json!({"id": SAMPLER_DELETE})); - assert_eq!(r["ok"], json!(false), "a greyed Delete does nothing: {r}"); - assert_eq!(samplers(&app).len(), 2, "nothing deleted, no sampler placed"); -} - -/// The right-click menu's Delete removes the sampler under the pointer, closes the menu, and -/// the samplers after it move up a number. -#[test] -fn delete_removes_the_sampler_under_the_pointer_and_renumbers_the_rest() { - let (mut app, ctx) = app(); - app.run("view.colorSamplers.add", json!({"x": 180, "y": 90})).unwrap(); - right_click(&mut app, &ctx, 120.0, 60.0); - assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); - let r = control(&mut app, &ctx, "ui.context.choose", json!({"id": SAMPLER_DELETE})); - assert_eq!(r["ok"], json!(true), "{r}"); - assert_eq!(samplers(&app), [[20.5, 20.5], [180.5, 90.5]], "#3 became #2"); - assert!(app.ui.canvas_tool_menu.is_none(), "choosing closes the menu"); - let listed = app.run("view.colorSamplers.list", json!({})).unwrap(); - assert_eq!(listed["samplers"][1]["number"], json!(2)); -} - -/// Delete never removes a different sampler when the list changes while the menu is open: one -/// deleted or moved meanwhile, or another document with a sampler at the same index and spot. -#[test] -fn delete_never_removes_another_sampler_after_the_list_changes_under_the_menu() { - let (mut app, ctx) = app(); - app.run("view.colorSamplers.add", json!({"x": 180, "y": 90})).unwrap(); - right_click(&mut app, &ctx, 120.0, 60.0); - assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); - // An agent deletes #1 while the menu is open: index 1 now names the old #3. - app.run("view.colorSamplers.delete", json!({"index": 0})).unwrap(); - let r = control(&mut app, &ctx, "ui.context.choose", json!({"id": SAMPLER_DELETE})); - assert_eq!(r["ok"], json!(false), "Delete greys out: {r}"); - assert_eq!(samplers(&app), [[120.5, 60.5], [180.5, 90.5]], "no other sampler is deleted"); - // The menu itself closes on the next frame. - right_click(&mut app, &ctx, 120.0, 60.0); - app.run("view.colorSamplers.move", json!({"index": 0, "x": 30, "y": 30})).unwrap(); - ctx.run_ui(Default::default(), |ui| crate::canvas_tool_menu::show(&mut app, ui.ctx())).textures_delta.clear(); - assert!(app.ui.canvas_tool_menu.is_none(), "a moved sampler closes the menu"); - // Another document with a sampler at the same index and spot: still not this menu's sampler. - right_click(&mut app, &ctx, 180.0, 90.0); - assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); - let menu = app.ui.canvas_tool_menu.clone().expect("the menu is open before switching documents"); - app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); - assert!(app.ui.canvas_tool_menu.is_none(), "switching documents closes the menu"); - for (x, y) in [(20, 20), (180, 90)] { - app.run("view.colorSamplers.add", json!({"x": x, "y": y})).unwrap(); - } - assert!(!crate::canvas_tool_menu::entry_enabled(&app, &menu, SAMPLER_DELETE), "another document's sampler"); -} - -#[test] -fn readout_rows_do_nothing_until_samplers_have_readout_modes() { - let (mut app, ctx) = app(); - right_click(&mut app, &ctx, 20.0, 20.0); - let before = app.session.active().unwrap().revision; - let r = control(&mut app, &ctx, "ui.context.choose", json!({"id": "colorSampler.readout.hsl"})); - assert_eq!(r["ok"], json!(false), "{r}"); - assert_eq!(app.session.active().unwrap().revision, before); - assert_eq!(samplers(&app).len(), 2); -} - -/// A sampler gone while the menu is open, a non-finite point, or no document at all: Delete -/// greys out and nothing panics. -#[test] -fn a_stale_sampler_or_odd_point_fails_gracefully() { - let (mut app, ctx) = app(); - right_click(&mut app, &ctx, 120.0, 60.0); - // The sampler went away while the menu was open: Delete greys out instead of removing another. - app.run("view.colorSamplers.clear", json!({})).unwrap(); - app.run("view.colorSamplers.add", json!({"x": 5, "y": 5})).unwrap(); - let menu = app.ui.canvas_tool_menu.clone().unwrap(); - assert!(!crate::canvas_tool_menu::entry_enabled(&app, &menu, SAMPLER_DELETE)); - crate::canvas_tool_menu::choose(&mut app, &ctx, SAMPLER_DELETE); - assert_eq!(samplers(&app), [[5.5, 5.5]]); - for p in [[f64::NAN, 5.0], [f64::INFINITY, 5.0], [5.0, f64::NEG_INFINITY]] { - assert_eq!(super::sampler_at(&app, p), None); - } - // No document: the menu opens greyed, nothing panics. - let mut empty = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); - empty.ui.tool = Tool::ColorSampler; - assert_eq!(super::sampler_at(&empty, [1.0, 1.0]), None); - if crate::canvas_tool_menu::open_at(&mut empty, &ctx, Tool::ColorSampler, [10.0, 10.0], Some([1.0, 1.0])) { - let menu = empty.ui.canvas_tool_menu.clone().unwrap(); - assert!(SAMPLER_MENU.iter().flatten().all(|(_, id)| !crate::canvas_tool_menu::entry_enabled(&empty, &menu, id))); - crate::canvas_tool_menu::choose(&mut empty, &ctx, SAMPLER_DELETE); - } -} - -#[test] -fn other_tools_keep_their_menus() { - let (mut app, ctx) = app(); - app.ui.tool = Tool::RectMarquee; - right_click(&mut app, &ctx, 20.0, 20.0); - let menu = app.ui.canvas_tool_menu.clone().expect("the selection menu"); - assert_eq!(crate::canvas_tool_menu::rows(&menu), crate::canvas_tool_menu::NO_SELECTION_MENU); - app.ui.canvas_tool_menu = None; - app.ui.tool = Tool::Pen; - right_click(&mut app, &ctx, 20.0, 20.0); - let menu = app.ui.canvas_tool_menu.clone().expect("the path menu"); - assert_eq!(crate::canvas_tool_menu::rows(&menu), crate::canvas_tool_menu::PEN_MENU); - app.ui.canvas_tool_menu = None; - // Outside the image the Color Sampler keeps the pasteboard menu. - app.ui.tool = Tool::ColorSampler; - right_click(&mut app, &ctx, 250.0, 40.0); - assert!(app.ui.canvas_tool_menu.as_ref().is_some_and(|m| m.pasteboard)); -} - -/// A real right-click on the canvas over sampler #2 opens the menu on it. -#[test] -fn canvas_right_click_opens_the_menu_on_the_sampler() { - let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_step_dt(1.0 / 60.0).build_eframe(|cc| { - PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); - app().0 - }); - h.run_steps(5); - let xf = crate::canvas::ViewXform::active(h.state()).unwrap(); - let at = xf.to_screen(120.5, 60.5); - h.event(Event::PointerMoved(at)); - h.run_steps(2); - for pressed in [true, false] { - h.input_mut().events.push(Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed, modifiers: Modifiers::NONE }); - h.run_steps(1); - } - h.run_steps(3); - let menu = h.state().ui.canvas_tool_menu.clone().expect("the Color Sampler menu opens"); - assert_eq!((menu.tool, menu.sampler), (Tool::ColorSampler, Some(1))); - assert_eq!(h.state().session.active().unwrap().color_samplers.len(), 2, "no sampler was placed or moved"); -} From 80344e35d7a6474d0d60dde5c8f18406e59b6026 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:51:38 +0100 Subject: [PATCH 6/9] fix(ui): retain document-bound canvas menus on current commands Pre-resolve commands.rs against the complete current main implementation, retaining the document identity check and canvas_tool_menu reset. Preserve upstream command refactors and CropFill changes. --- crates/ui-egui/src/app/commands.rs | 87 +++++++++--------------------- 1 file changed, 25 insertions(+), 62 deletions(-) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index f2fed52016..f5b296d7d3 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -1,6 +1,6 @@ use super::{ - DocId, PhotocraftApp, Tool, Value, actions, canvas, delete_layer_prompt, dock, gpu_canvas, jobs_ui, json, mask_trash_prompt, notices, panel_docking, - smart_svg_ui, state, transform_tool, type_transform, vector_ui, + DocId, PhotocraftApp, Value, actions, canvas, delete_layer_prompt, gpu_canvas, jobs_ui, json, mask_trash_prompt, notices, panel_docking, smart_svg_ui, + state, transform_tool, type_transform, vector_ui, }; impl PhotocraftApp { @@ -28,16 +28,8 @@ impl PhotocraftApp { if gate.is_some() { self.session.authorize = None; } - if let Ok(reply) = &result { - if library_change { - actions::library_selection_changed(self); - } else if id == "actions.load" { - actions::library_slots_changed(self); - } else if id == "actions.duplicate" - && let Some(slot) = reply["setSlot"].as_u64().and_then(|slot| usize::try_from(slot).ok()) - { - actions::library_slot_inserted(self, slot); - } + if library_change && result.is_ok() { + actions::library_changed(self); } // An explicit channel target (⌘2, ⌘\, ⌘3…) decides what the Layers panel targets too: // ⌘2 after the mask was targeted goes back to the layer's pixels. @@ -112,15 +104,10 @@ impl PhotocraftApp { } // Document exports read committed pixels, not the pending Free Transform preview. // Check on execution (also dialog OK and automation), leaving Folder processing usable. - if id == "file.scripts.imageProcessor" - && self.ui.transform.is_some() - && match params.get("source").and_then(Value::as_str) { - Some("open") => true, - Some("current") => self.transform_preview.as_ref().is_none_or(|preview| self.session.active().is_some_and(|st| st.doc.id == preview.doc.id)), - _ => false, - } + if id == crate::dialogs::image_processor_ui::COMMAND + && crate::dialogs::image_processor_ui::waits_for_transform(self, params.get("source").and_then(Value::as_str)) { - return Err("Commit or cancel the transform first".into()); + return Err(tl!("Commit or cancel the transform first").into()); } if let Some(r) = transform_tool::intercept(self, id) { return r; @@ -204,7 +191,7 @@ impl PhotocraftApp { let r = if id == "actions.play" { actions::play(self, ¶ms) } else if photocraft_engine::actions_cmds::shell_view_command(id) { - actions::run_view(self, id, params) + actions::runner::run_view(self, id, params) } else { jobs_ui::run(self, id, params) }; @@ -243,12 +230,6 @@ impl PhotocraftApp { /// Keep one view per document, in tab order: a view and its windows stay with their document /// when tabs move (`document.move`) or close. - /// The tool pointer events go to: a held temporary tool when there is one (⌘ is the Move - /// tool, `hold_keys::cmd_moves`), else the selected tool. - pub fn active_tool(&self) -> state::Tool { - self.tool_override.unwrap_or(self.ui.tool) - } - /// Selects the newly attached type path on composite channel target so the path becomes immediately editable. fn select_attached_type_path(&mut self, command: &str, result: &Result) { if command != "type.attachToPath" { @@ -297,12 +278,7 @@ impl PhotocraftApp { if result.is_ok() && creates_adjustment_or_fill { // Properties comes to the front, shown and expanded, so the new layer's settings can // be edited at once, as in Photoshop (#4028). The layer is made whatever happens here. - if self.ui.docking.is_some() { - let _ = panel_docking::command(self, "window.panel.activate", &json!({"panel": "properties"})); - } else { - self.ui.dock_tabs.properties = 0; - dock::reveal(self, dock::Group::Properties); - } + let _ = panel_docking::show_panel(self, "properties", Some(true)); } // Making a new selection reveals its outline after View > Extras was hidden (#5597). // These interactive selection commands complete inline; a failed command, deselection, @@ -360,7 +336,6 @@ impl PhotocraftApp { /// Reconciles canvas view state with open documents in the session. pub fn sync_views(&mut self) { - crate::type_path_placement::cancel_stale(self); // The Paths panel selection and canvas context menu belong to the active document. // Ordinary edits replace the snapshot and advance its revision; a replaced snapshot // without a newer revision is a reopened document, even with the same ID. @@ -373,7 +348,7 @@ impl PhotocraftApp { && id != old_id && self.view_docs.contains(id) { - self.ui.tool_options.crop_content_aware = false; + self.ui.tool_options.crop.fill = craft::draw::ui::crop::CropFill::Background; } let same_document = match (&self.path_document, &document) { (Some((old_id, old_revision, old_source)), Some((id, revision, source))) => old_id == id && (revision > old_revision || old_source.ptr_eq(source)), @@ -385,25 +360,11 @@ impl PhotocraftApp { self.ui.canvas_tool_menu = None; } self.path_document = document; - // A shape box handle drag belongs to its document, revision and tool. - crate::shape_bounds_box::cancel_stale(self); vector_ui::cancel_stale_pen(self); crate::direct_select::cancel_stale(self); - canvas::cancel_stale_vector_drag(self); type_transform::cancel_stale(self); crate::cam_transform::cancel_stale(self); - crate::lasso_ui::cancel_stale(self); - crate::retouch_ui::cancel_stale(self); - // A polygon under construction belongs to the Polygonal Lasso tool, not the next tool. - if self.ui.tool != Tool::PolygonLasso { - self.ui.polygon.clear(); - self.ui.polygon_mode.clear(); - } - // ... and to the document it was started on. - crate::canvas::polygon_cancel_stale(self); - crate::crop_ui::cancel_stale(self); crate::distort_ui::cancel_stale(self); - crate::perspective_crop_ui::cancel_stale(self); // A pen path under construction belongs to the document it was started on too. vector_ui::cancel_stale(self); let ids: Vec = self.session.documents().iter().map(|d| d.doc.id).collect(); @@ -419,28 +380,30 @@ impl PhotocraftApp { } } self.ui.views = views.into_iter().map(Option::unwrap_or_default).collect(); - self.ui.windows.retain_mut(|w| now(w.document).map(|d| w.document = d).is_some()); + canvas::document_windows::sync_documents(self, &ids); if !self.session.prefs().workspace.open_documents_as_tabs { - let new_docs: Vec = ids.iter().enumerate().filter(|(_, id)| !self.view_docs.contains(id)).map(|(i, _)| i).collect(); - for &idx in &new_docs { - if !self.ui.windows.iter().any(|w| w.document == idx) { - crate::view_cmds::float_window(self, idx, idx, false); + let new_docs: Vec = ids.iter().filter(|id| !self.view_docs.contains(id)).copied().collect(); + let ctx = self.ctx().clone(); + for id in new_docs { + // A document already in a floating window keeps it. + if !crate::view_cmds::document_is_floating(self, id) { + crate::view_cmds::invoke(self, &ctx, "window.arrange.floatInWindow", &json!({"document": id.0})); } } } self.canvases.retain(|(doc, _), _| ids.contains(doc)); + self.raster_logs.retain(|(doc, _), _| ids.contains(doc)); self.navigator_textures.retain(|doc, _| ids.contains(doc)); - self.snapshot_thumbs.retain(|(doc, _), _| ids.contains(doc)); // Closing a document cancels its page work; its GPU pages go with `retain_gpu_documents`. self.streams.retain(|doc, _| ids.contains(doc)); - self.view_docs = ids; - self.prune_thumbs(); - self.sync_mask_targets(); - // Channel-view textures outlive a hidden view (cheap re-show), not their document. - if !self.channel_views.is_empty() { - let docs = self.session.documents(); - self.channel_views.retain(|id, _| docs.iter().any(|d| d.doc.id.0 == *id)); + // A parameter dialog holds a target in a document that has left the session: it closes with it. + let closed: Vec = self.view_docs.iter().filter(|d| !ids.contains(d)).cloned().collect(); + if !closed.is_empty() { + let ctx = self.ctx().clone(); + crate::dialogs::cancel_for_closed(self, &ctx, &closed); } + self.view_docs = ids; + self.sync_mask_targets(); // With no document left, no canvas paints the Levels clipping display to drop its cache. if self.session.documents().is_empty() { self.levels_clipping = None; From 7de3fedcccc08f6052fdc74eff6ccf1a8b1d32da Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:56:00 +0100 Subject: [PATCH 7/9] test(ui): use the current canvas menu opening API Migrate the retained Hand and Zoom document-switch regressions from removed open_view to open_at, using the current modifier, screen point and document point types. Remove the obsolete test context. --- crates/ui-egui/src/view_sync_tests.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/view_sync_tests.rs b/crates/ui-egui/src/view_sync_tests.rs index 91c6a8b1ca..b81388cc3e 100644 --- a/crates/ui-egui/src/view_sync_tests.rs +++ b/crates/ui-egui/src/view_sync_tests.rs @@ -51,8 +51,7 @@ fn switching_documents_closes_the_canvas_view_menu() { for tool in [crate::Tool::Zoom, crate::Tool::Hand] { let mut app = app_with_two_documents(); app.ui.tool = tool; - let ctx = egui::Context::default(); - assert!(crate::canvas_tool_menu::open_view(&mut app, &ctx, tool, [10.0, 10.0], [20.0, 20.0])); + assert!(crate::canvas_tool_menu::open_at(&mut app, tool, Default::default(), egui::pos2(10.0, 10.0), [20.0, 20.0], None)); app.sync_views(); assert!(app.ui.canvas_tool_menu.is_some(), "ordinary sync keeps the menu"); app.run("layer.new.layer", json!({})).unwrap(); @@ -75,7 +74,7 @@ fn closing_a_tab_keeps_the_canvas_menu_only_for_its_own_document() { } app.ui.tool = crate::Tool::Hand; let document = app.session.active().unwrap().doc.id; - assert!(crate::canvas_tool_menu::open_view(&mut app, &egui::Context::default(), crate::Tool::Hand, [10.0, 10.0], [20.0, 20.0])); + assert!(crate::canvas_tool_menu::open_at(&mut app, crate::Tool::Hand, Default::default(), egui::pos2(10.0, 10.0), [20.0, 20.0], None)); app.run("file.close", json!({"document": 0})).unwrap(); assert_eq!(app.session.active_index(), Some(0), "the survivor occupies the first slot"); assert_eq!(app.session.active().unwrap().doc.id == document, !close_menu_document); From b6428ed1043a17fa290cc0b15653feba922ab535 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:57:02 +0100 Subject: [PATCH 8/9] test(ui): assert document-switch fixtures open view menus Assert the current public right-click route opens MenuKind::View before checking document identity, ordinary edits and tab closure. This keeps future routing changes from weakening the retained regressions. --- crates/ui-egui/src/view_sync_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-egui/src/view_sync_tests.rs b/crates/ui-egui/src/view_sync_tests.rs index b81388cc3e..be36297dd8 100644 --- a/crates/ui-egui/src/view_sync_tests.rs +++ b/crates/ui-egui/src/view_sync_tests.rs @@ -52,6 +52,7 @@ fn switching_documents_closes_the_canvas_view_menu() { let mut app = app_with_two_documents(); app.ui.tool = tool; assert!(crate::canvas_tool_menu::open_at(&mut app, tool, Default::default(), egui::pos2(10.0, 10.0), [20.0, 20.0], None)); + assert!(matches!(app.ui.canvas_tool_menu.as_ref().map(|menu| &menu.kind), Some(crate::canvas_tool_menu::MenuKind::View))); app.sync_views(); assert!(app.ui.canvas_tool_menu.is_some(), "ordinary sync keeps the menu"); app.run("layer.new.layer", json!({})).unwrap(); @@ -75,6 +76,7 @@ fn closing_a_tab_keeps_the_canvas_menu_only_for_its_own_document() { app.ui.tool = crate::Tool::Hand; let document = app.session.active().unwrap().doc.id; assert!(crate::canvas_tool_menu::open_at(&mut app, crate::Tool::Hand, Default::default(), egui::pos2(10.0, 10.0), [20.0, 20.0], None)); + assert!(matches!(app.ui.canvas_tool_menu.as_ref().map(|menu| &menu.kind), Some(crate::canvas_tool_menu::MenuKind::View))); app.run("file.close", json!({"document": 0})).unwrap(); assert_eq!(app.session.active_index(), Some(0), "the survivor occupies the first slot"); assert_eq!(app.session.active().unwrap().doc.id == document, !close_menu_document); From a419dad12103bed5998cb9b281c9e265b3f057a4 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:04:40 +0100 Subject: [PATCH 9/9] test(ui): retain the cross-document sampler Delete guard Capture the original sampler menu before switching documents, retain the immediate-dismissal assertion, and verify that its Delete action stays disabled after another document receives matching sampler indices and positions. Addresses the current CodeRabbit regression-coverage nitpick. --- crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs b/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs index 16c1bb2f03..2389fd03e4 100644 --- a/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs +++ b/crates/ui-egui/src/tools/analysis/sampler_menu_tests.rs @@ -43,11 +43,13 @@ fn delete_never_removes_another_sampler_after_the_list_changes_under_the_menu() // Another document with a sampler at the same index and spot: still not this menu's sampler. right_click(&mut app, 180.0, 90.0); assert_eq!(app.ui.canvas_tool_menu.as_ref().and_then(|m| m.sampler), Some(1)); + let original_menu = app.ui.canvas_tool_menu.clone().unwrap(); app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); assert!(app.ui.canvas_tool_menu.is_none(), "switching documents closes the menu"); for (x, y) in [(20, 20), (180, 90)] { app.run("view.colorSamplers.add", json!({"x": x, "y": y})).unwrap(); } + assert!(!crate::canvas_tool_menu::entry_enabled(&app, &original_menu, SAMPLER_DELETE), "the original menu cannot delete another document's sampler"); crate::canvas_tool_menu::close_stale(&mut app); crate::canvas_tool_menu::choose(&mut app, &ctx, SAMPLER_DELETE); assert_eq!(samplers(&app).len(), 2, "another document's sampler is not deleted");