mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #11327 into the merge queue batch
fix(ui): close canvas menus when the active document changes
This commit is contained in:
commit
bb864668bf
4 files changed
+49
-5
No files matched your search
@@ -343,9 +343,9 @@ impl PhotocraftApp {
|
||||
|
||||
/// Reconciles canvas view state with open documents in the session.
|
||||
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)));
|
||||
// Crop's Fill goes back to its default entry when another document that was already open
|
||||
// becomes active (a tab switch, or closing the active one), as in the reference
|
||||
@@ -364,6 +364,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);
|
||||
|
||||
@@ -43,10 +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");
|
||||
|
||||
@@ -44,3 +44,42 @@ 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;
|
||||
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();
|
||||
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_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);
|
||||
assert_eq!(app.ui.canvas_tool_menu.is_some(), !close_menu_document, "only a menu for the surviving document stays open");
|
||||
}
|
||||
}
|
||||
@@ -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) |
|
||||
|
||||
Reference in new issue
Block a user