From 83dcfd287dbdbb8d691d9f0b6cde97e572d79e3d Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 29 Nov 2026 23:22:54 +0100 Subject: [PATCH] Canvas menu tests: a switch away closes the menu for good, as main's sync_views does Co-Authored-By: Claude Opus 5.5 --- .../canvas/canvas_tool_menu/document_switch_tests.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/document_switch_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/document_switch_tests.rs index 2a97a7d790..a299e8effa 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/document_switch_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/document_switch_tests.rs @@ -1,6 +1,6 @@ //! #12359: a canvas right-click menu belongs to the document it was opened on. When another //! document becomes active it closes (`close_stale`), `ui.context.choose` refuses its rows with an error -//! and closes it, and neither document changes. With the same document active it works as before. +//! and closes it, and neither document changes. With its document still active it works as before. use serde_json::{Value, json}; @@ -67,7 +67,7 @@ fn a_layer_row_chosen_after_a_document_switch_runs_nowhere() { #[test] fn the_menu_closes_when_another_document_becomes_active() { - let (mut app, ctx) = two_documents(Tool::RectMarquee); + let (mut app, _ctx) = two_documents(Tool::RectMarquee); right_click(&mut app, 16.0, 16.0); let menu = app.ui.canvas_tool_menu.clone().unwrap(); assert!(menu.doc.is_some(), "the menu records its document"); @@ -75,6 +75,8 @@ fn the_menu_closes_when_another_document_becomes_active() { activate(&mut app, 1); assert!(!available(&app, &menu, "layer.new.layerViaCut"), "no row is available on another document"); assert!(!entry_enabled(&app, &menu, "layer.new.layerViaCut"), "and none lists as enabled"); + // Even when the switch reached the menu before `sync_views` did, the next frame closes it. + app.ui.canvas_tool_menu = Some(menu); close_stale(&mut app); assert!(app.ui.canvas_tool_menu.is_none(), "the next frame closes it"); } @@ -84,9 +86,8 @@ fn the_menu_still_works_on_its_own_document() { let (mut app, ctx) = two_documents(Tool::RectMarquee); right_click(&mut app, 16.0, 16.0); let layers = app.session.active().unwrap().doc.layers.len(); - // A switch away and back: the menu's document is active again. - activate(&mut app, 1); - activate(&mut app, 0); + // Its document stays active: the recorded document matches, so the row runs. (A switch away + // closes the menu for good, `sync_views`, even when the document comes back.) let r = choose(&mut app, &ctx, "layer.new.layerViaCut"); assert_eq!(r["ok"], true, "{r}"); assert_eq!(app.session.active().unwrap().doc.layers.len(), layers + 1, "Layer Via Cut ran on A");