From 8f166584984e63def66ab3a7308c43b477f57865 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 07:07:44 -0800 Subject: [PATCH] Fix #7906: a dialog that opens closes the Command Palette, flyouts and menus A dialog opened without a press in the window, such as a pick in the macOS menu bar, an automation command or a run that ends in a dialog, left the Command Palette open over it, and the palette's search field kept the keyboard focus. A tool group's flyout, the All Tools drawer and an open menu or popup also stayed open above the dialog's backdrop. The palette could also be opened over an open dialog from the macOS menu bar or by an automation command, and its field then took the keyboard focus from the dialog. In the pass a dialog, the About window, a file dialog, the update prompt or a progress window opens, the app now closes the palette, the flyout, the drawer and any open popup. A flyout, drawer or menu opened while a progress window is waiting to appear also closes when it appears. While such a window is open, the palette stays closed, and the widget that had the focus before the palette opened does not take it back under the window. A palette opened after the window closes stays open until the next window opens. --- crates/ui-egui/src/app.rs | 2 + crates/ui-egui/src/dialogs/modal.rs | 13 ++ crates/ui-egui/src/palette.rs | 194 +++++++++++++++++++++++++++- crates/ui-egui/src/panel_docking.rs | 34 +++++ docs/target-app-parity.md | 1 + 5 files changed, 239 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index e3d2a13d64..b2757ca2fc 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -628,6 +628,8 @@ impl VectorcraftApp { plugin_runs::show(self, &ctx); trace_runs::show(self, &ctx); opening::show(self, &ctx); + // After every window this pass may open, and before the palette's field takes the keyboard. + panel_docking::close_overlays_for_modal(self, &ctx); palette::show(self, &ctx); // After every panel had its chance to draw in this pass. crate::panels::three_d::end_stale_drag(self, &ctx); diff --git a/crates/ui-egui/src/dialogs/modal.rs b/crates/ui-egui/src/dialogs/modal.rs index f72383068e..c7bedbe2b1 100644 --- a/crates/ui-egui/src/dialogs/modal.rs +++ b/crates/ui-egui/src/dialogs/modal.rs @@ -25,6 +25,8 @@ pub(crate) fn show_at(ctx: &egui::Context, title: &str, id: Id, initial: Vec2 // Not focusable (`Sense::click()` is): Tab goes through the dialog's controls, not the backdrop. ui.allocate_rect(ctx.content_rect(), egui::Sense::CLICK); }); + let pass = ctx.cumulative_pass_nr(); + ctx.data_mut(|d| d.insert_temp(drawn_pass_id(), pass)); let shown = egui::Window::new(title) .id(id) .order(egui::Order::Foreground) @@ -44,6 +46,17 @@ pub(crate) fn backdrop() -> egui::LayerId { egui::LayerId::new(egui::Order::Middle, Id::unique("modal-dim")) } +/// The key of the pass in which [`show_at`] last drew a modal window. +fn drawn_pass_id() -> Id { + Id::unique("modal-drawn-pass") +} + +/// Whether [`show_at`] drew a modal window in this pass. Unlike the backdrop's visibility, which +/// also counts the last pass, it is false in the pass after the window closes. +pub(crate) fn drawn_this_pass(ctx: &egui::Context) -> bool { + ctx.data(|d| d.get_temp::(drawn_pass_id())) == Some(ctx.cumulative_pass_nr()) +} + /// The dialog's heading, which also moves the window ([`drag_band`]). pub(crate) fn heading(ui: &mut egui::Ui, text: &str) { let t = Tokens::get(ui.ctx()); diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 5c531019ce..74acb1bfb0 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -563,8 +563,9 @@ pub(crate) fn recent_list_open(ctx: &egui::Context) -> bool { pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // The widget that had the keyboard focus when the palette opened takes it back when the palette - // closes, unless a pick opened a dialog, which focuses its own first field, or the press that - // closed it focused another widget, such as a field in a window above the backdrop. + // closes, unless a modal window is up (a pick opened a dialog, which focuses its own first + // field, or a window that opened closed the palette), or the press that closed it focused + // another widget, such as a field in a window above the backdrop. let focus_id = egui::Id::unique("palette-focus-before"); let field_id = egui::Id::unique("palette-field"); if !app.ui.palette_open { @@ -575,7 +576,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { }); let now = ctx.memory(|m| m.focused()); if let Some(Some(before)) = ctx.data_mut(|d| d.remove_temp::>(focus_id)) - && app.ui.dialog.is_none() + && !crate::panel_docking::modal_window_up(app, ctx) && (now.is_none() || now == field) { ctx.memory_mut(|m| m.request_focus(before)); @@ -2292,6 +2293,38 @@ mod tests { assert!(labels(&nodes).contains(&footer(n, n)), "{:?}", labels(&nodes)); } + /// When a modal window that is not a dialog, such as the About window, closes the palette, the + /// widget under the window's backdrop does not get the keyboard focus back. + #[test] + fn a_modal_window_that_closes_the_palette_keeps_the_focus_from_the_widget_under_it() { + let ctx = egui::Context::default(); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let mut text = String::new(); + let field = egui::Id::unique("other field"); + let mut frame = |app: &mut VectorcraftApp, focus: bool| { + ctx.run_ui(egui::RawInput::default(), |ui| { + let r = ui.add(egui::TextEdit::singleline(&mut text).id(field)); + if focus { + r.request_focus(); + } + show(app, ui.ctx()); + }) + .textures_delta + .clear(); + }; + frame(&mut app, true); + frame(&mut app, false); + app.ui.palette_open = true; + frame(&mut app, false); + frame(&mut app, false); + // As `panel_docking::close_overlays_for_modal` does when the About window opens. + app.ui.about = true; + app.ui.palette_open = false; + frame(&mut app, false); + frame(&mut app, false); + assert_ne!(ctx.memory(|m| m.focused()), Some(field), "the field under the About window does not take the focus"); + } + /// The widget that had the keyboard focus when the palette opened has it again once the /// palette closes. #[test] @@ -2387,6 +2420,9 @@ mod tests { /// app, as a progress window is drawn, and count its clicks. above: Option, above_clicks: usize, + /// Draw a modal window over the backdrop before the app's windows, as a progress window + /// of a plug-in, trace or open run is drawn. + progress: bool, } impl Window { @@ -2398,7 +2434,7 @@ mod tests { assert!(!app.session.doc().unwrap().selection.is_empty()); let ctx = egui::Context::default(); ctx.enable_accesskit(); - let mut window = Window { app, ctx, time: 0.0, above: None, above_clicks: 0 }; + let mut window = Window { app, ctx, time: 0.0, above: None, above_clicks: 0, progress: false }; window.frame(vec![]); window.frame(vec![]); window @@ -2410,9 +2446,13 @@ mod tests { let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, WINDOW); let input = egui::RawInput { time: Some(self.time), screen_rect: Some(screen), events, ..Default::default() }; let app = &mut self.app; - let (above, clicks) = (self.above, &mut self.above_clicks); + let (above, clicks, progress) = (self.above, &mut self.above_clicks, self.progress); let mut out = self.ctx.run_ui(input, |ui| { app.logic(ui.ctx()); + if progress { + let id = egui::Id::unique("test-progress"); + crate::dialogs::modal::show_at(ui.ctx(), "Progress", id, egui::Vec2::ZERO, 12, |ui| ui.label("Working")); + } app.ui(ui); if let Some(at) = above { let area = egui::Area::new(egui::Id::unique("test-above")).order(egui::Order::Foreground).fixed_pos(at); @@ -2484,6 +2524,150 @@ mod tests { assert_eq!(window.selection(), before, "the click does not reach the canvas"); } + /// #7906: a pick in the macOS menu bar that opens a dialog closes the palette, and the search + /// field does not keep the keyboard from the dialog. + #[test] + fn a_dialog_opened_from_the_system_menu_closes_the_palette() { + let mut window = Window::new(); + window.app.ui.palette_open = true; + window.frame(vec![]); + window.frame(vec![]); + let field = window.ctx.data(|d| d.get_temp::(egui::Id::unique("palette-field"))).expect("the search field is drawn"); + assert_eq!(window.ctx.memory(|m| m.focused()), Some(field), "the search field has the keyboard"); + menus::invoke_from_system_menu(&mut window.app, &window.ctx, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog: {}", window.app.ui.status); + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the dialog closes the palette"); + window.frame(vec![]); + assert!(window.app.ui.dialog.is_some(), "the dialog stays open"); + assert_ne!(window.ctx.memory(|m| m.focused()), Some(field), "the search field does not keep the keyboard"); + } + + /// #7906: with the palette open, the About window that opens without a press closes the palette. + #[test] + fn the_about_window_closes_the_palette() { + let mut window = Window::new(); + window.app.ui.palette_open = true; + window.frame(vec![]); + menus::invoke_from_system_menu(&mut window.app, &window.ctx, "help.about", json!({})); + assert!(window.app.ui.about, "About opens"); + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the About window closes the palette"); + } + + /// #7906: a window drawn over the modal backdrop, as a plug-in, trace or open run's progress + /// window is, closes the palette in the pass it first draws. + #[test] + fn a_progress_window_closes_the_palette() { + let mut window = Window::new(); + window.app.ui.palette_open = true; + window.frame(vec![]); + assert!(window.app.ui.palette_open, "the palette is open"); + window.progress = true; + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the progress window closes the palette"); + } + + /// #7906: the palette opened from the macOS menu bar while a dialog is open closes again, and its + /// search field does not take the keyboard from the dialog. + #[test] + fn the_palette_opened_over_a_dialog_closes() { + let mut window = Window::new(); + menus::invoke(&mut window.app, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog: {}", window.app.ui.status); + window.frame(vec![]); + window.frame(vec![]); + let before = window.ctx.memory(|m| m.focused()); + menus::invoke_from_system_menu(&mut window.app, &window.ctx, "help.commandPalette", json!({})); + assert!(window.app.ui.palette_open, "the command opens the palette"); + window.frame(vec![]); + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the dialog keeps the palette closed"); + assert!(window.app.ui.dialog.is_some(), "the dialog stays open"); + let field = window.ctx.data(|d| d.get_temp::(egui::Id::unique("palette-field"))); + let now = window.ctx.memory(|m| m.focused()); + assert!(field.is_none() || now != field, "the search field does not take the keyboard"); + assert_eq!(now, before, "the dialog keeps its focus"); + } + + /// #7906 as reported: with the palette open, a click on the Effect menu in the window's menu bar + /// closes the palette, and a dialog opened afterwards is not under it. + #[test] + fn a_click_on_the_menu_bar_closes_the_palette_before_a_dialog_opens() { + let mut window = Window::new(); + window.app.ui.palette_open = true; + let nodes = window.frame(vec![]); + window.click(button_at(&nodes, "Effect")); + assert!(!window.app.ui.palette_open, "the click on the menu bar closes the palette"); + menus::invoke(&mut window.app, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog: {}", window.app.ui.status); + window.frame(vec![]); + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the palette stays closed over the dialog"); + } + + /// Opens `overlay` ("flyout", "drawer" or "menu") in a new window, then opens Move… without a + /// press, as the macOS menu bar or an automation command does: whether the overlay is still open. + fn overlay_open_after_a_dialog_opens(overlay: &str) -> bool { + let mut window = Window::new(); + match overlay { + "flyout" => { + window.app.ui.flyout = Some(0); + let tools = vec!["rectangle".to_string(), "ellipse".to_string()]; + window.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("flyout-tools"), tools)); + } + "drawer" => window.app.ui.tools_drawer = true, + _ => { + let nodes = window.frame(vec![]); + window.click(button_at(&nodes, "Object")); + } + } + window.frame(vec![]); + let open = |w: &Window| w.app.ui.flyout.is_some() || w.app.ui.tools_drawer || egui::Popup::is_any_open(&w.ctx); + assert!(open(&window), "the {overlay} is open"); + menus::invoke(&mut window.app, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog: {}", window.app.ui.status); + window.frame(vec![]); + open(&window) + } + + /// #7906: a dialog that opens without a press closes a tool group's flyout. + #[test] + fn a_dialog_opened_without_a_press_closes_a_flyout() { + assert!(!overlay_open_after_a_dialog_opens("flyout"), "the dialog closes the flyout"); + } + + /// #7906: a dialog that opens without a press closes the All Tools drawer. + #[test] + fn a_dialog_opened_without_a_press_closes_the_tools_drawer() { + assert!(!overlay_open_after_a_dialog_opens("drawer"), "the dialog closes the drawer"); + } + + /// #7906: a dialog that opens without a press closes an open menu. + #[test] + fn a_dialog_opened_without_a_press_closes_a_menu() { + assert!(!overlay_open_after_a_dialog_opens("menu"), "the dialog closes the menu"); + } + + /// The palette opened in the pass after a dialog closes stays open, and the next dialog to open, + /// one pass later, closes it. + #[test] + fn the_palette_opened_as_a_dialog_closes_stays_open_until_the_next_dialog() { + let mut window = Window::new(); + menus::invoke(&mut window.app, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog: {}", window.app.ui.status); + window.frame(vec![]); + window.frame(vec![]); + crate::dialogs::cancel(&mut window.app); + window.app.ui.palette_open = true; + window.frame(vec![]); + assert!(window.app.ui.palette_open, "the palette stays open"); + menus::invoke(&mut window.app, "object.move", json!({})); + assert!(window.app.ui.dialog.is_some(), "Move… opens its dialog again: {}", window.app.ui.status); + window.frame(vec![]); + assert!(!window.app.ui.palette_open, "the next dialog closes the palette"); + } + /// A click on another control outside the popup closes the popup and does not press the /// control. #[test] diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 0a4f01879d..b25c334370 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -1305,6 +1305,40 @@ pub(crate) fn modal_open(app: &VectorcraftApp, ctx: &egui::Context) -> bool { || ctx.memory(|m| m.areas().is_visible(&crate::dialogs::modal::backdrop())) } +/// Is a modal window open in this pass: a dialog, the About window, a file dialog, the update +/// prompt, or a window such as a progress window drawn over the modal backdrop in this pass? +pub(crate) fn modal_window_up(app: &VectorcraftApp, ctx: &egui::Context) -> bool { + app.ui.dialog.is_some() + || app.ui.about + || app.file_dialog_open() + || crate::updates_ui::blocks_input(app) + || crate::dialogs::modal::drawn_this_pass(ctx) +} + +/// The key of whether a modal window was up in the last pass ([`close_overlays_for_modal`]). +fn modal_window_up_id() -> egui::Id { + egui::Id::unique("modal-window-up") +} + +/// While a modal window is up ([`modal_window_up`]), keeps the command palette closed, so a palette +/// opened over it from the macOS menu bar or by an automation command does not take the keyboard +/// from the window. In the pass the window opens, also closes a tool group's flyout, the All Tools +/// drawer and any open popup, whatever opened the window: a press in the window, a pick in the +/// macOS menu bar, an automation command or a run that ends in a dialog. Popups the window itself +/// opens later stay open. Called after every window of the pass has drawn. +pub(crate) fn close_overlays_for_modal(app: &mut VectorcraftApp, ctx: &egui::Context) { + let up = modal_window_up(app, ctx); + let was = ctx.data_mut(|d| std::mem::replace(d.get_temp_mut_or_default::(modal_window_up_id()), up)); + if up { + app.ui.palette_open = false; + } + if up && !was { + app.ui.flyout = None; + app.ui.tools_drawer = false; + egui::Popup::close_all(ctx); + } +} + /// Keys, text and clipboard events that a floating panel's own OS window left over run the main /// window's shortcuts, tool keys and clipboard on its next frame ([`VectorcraftApp::raw_input_hook`]). /// craft-ui forwards nothing while a field in that window has the keyboard. A field of the main diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index db61a96f73..5562356691 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1373,6 +1373,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur The Command Palette leaves out the engine commands that Edit › Keyboard Shortcuts marks as needing a value: a query with no default key and no menu bar item (Document JSON, Select All Unused in the Brushes panel), and a command that needs a value no menu item gives (Window › Transparency's `transparency.set`, Document Setup's units). Of those, it still lists the ones whose pick does something without params: Stop Script, Clear Script Console, Clear Plug-in Cache, Reset Preferences, Forget Import Matches, Begin Undo Group and End Undo Group, the six Save … Preset commands, Delete Gradient Preset, Pixel Snapping Options…, the Asset Export commands, New Symbol, Gradient Vector, Define Perspective Grid and Select Slice. Each panel is a result under Window › Show Panel, whose pick shows the panel and leaves one already showing as it is, and each Effect menu item is a result, named as the menu names it, whose pick runs what its menu item runs; while the item is dimmed, no dialog opens and the status line says why. A query of "layers" shows the Layers panel first. The search field's hint and the app bar's search tooltip say "Search commands, tools, panels and effects" (`palette` tests `the_palette_leaves_out_the_commands_a_pick_cannot_run`, `a_pick_of_a_session_command_runs_it`, `a_panel_is_a_result_whose_pick_shows_it`, `an_effect_is_a_result_whose_pick_runs_its_menu_item`; `shortcut_editor` test `a_command_given_a_key_that_needs_a_value_is_no_pick`). The Command Palette shows each result as a 20-point row, with no gap between rows, and shows 12 rows at a time in a list that scrolls; a short window shows fewer. A name too long for its row ends with "…". The list holds up to 50 results, and the line under it says how many matched ("14 results", "50 of 120 results. Keep typing to narrow them." or "No commands match"). Up and Down move the highlight and wrap at the ends, Page Up and Page Down move it by the rows shown and stop at the ends, and the highlighted row scrolls into view; after a scroll with the wheel, the highlight moves to the nearest row in view. A click anywhere on a row runs it. Screen readers stay on the search field, whose description names the highlighted result and its place among every match ("2 of 14: …", or "2 of 120: …" when the list holds 50); the rows are list items, the highlighted one selected, and the keyboard focus goes back to where it was when the palette closes, unless a pick opened a dialog (`palette` tests `results_are_compact_rows_that_touch`, `the_footer_counts_the_results`, `with_no_match_enter_runs_nothing`, `the_sixteenth_result_is_reached_by_keyboard_and_runs`, `page_keys_move_by_a_page_without_wrapping`, `a_wheel_scroll_keeps_the_highlight_in_view`, `the_row_under_the_pointer_is_the_one_highlighted`, `a_long_name_ends_with_an_ellipsis`, `the_popup_stays_inside_a_short_window`, `a_click_anywhere_on_a_row_runs_it`, `screen_readers_hear_the_highlighted_result_and_the_count`, `closing_gives_the_focus_back`). A press of any pointer button outside the Command Palette closes it: a click, a right-click or the start of a drag. While the palette is open, the canvas, the toolbars, the docked panels and the app bar under it do not respond to the pointer, so the press that closes the palette does not press a tool button or another control there. A window drawn above them, such as a progress window, still gets its click, and that click also closes the palette (`palette` tests `a_click_on_the_canvas_closes_the_palette`, `a_click_on_another_control_closes_the_palette_without_pressing_it`, `a_right_click_or_a_drag_outside_closes_the_palette`, `a_click_on_a_window_above_closes_the_palette_and_reaches_it`, `the_click_that_opens_the_palette_does_not_close_it`). + A modal window that opens without a press in the window (a dialog opened from the macOS menu bar or by an automation command, the About window, a file dialog, the update prompt, or the progress window of a plug-in, trace or open run) closes the Command Palette, a tool group's flyout, the All Tools drawer and any open menu or popup in the pass it opens. While such a window is open, the palette stays closed, so opening it from the macOS menu bar or by an automation command does not take the keyboard from the window; it opens again once the window closes (`palette` tests `a_dialog_opened_from_the_system_menu_closes_the_palette`, `the_about_window_closes_the_palette`, `a_progress_window_closes_the_palette`, `the_palette_opened_over_a_dialog_closes`, `a_click_on_the_menu_bar_closes_the_palette_before_a_dialog_opens`, `a_dialog_opened_without_a_press_closes_a_flyout`, `a_dialog_opened_without_a_press_closes_the_tools_drawer`, `a_dialog_opened_without_a_press_closes_a_menu`, `the_palette_opened_as_a_dialog_closes_stays_open_until_the_next_dialog`). The Command Palette ranks its results by how well they match. A query that is a result's id lists that result first (`view.goto1` lists Saved View 1 above Saved View 10); then come results whose name is the query, results whose name without its menu path starts with it, and results whose initials it is ("ea" finds Export As…). Within each of those, a result where every word of the query is a whole word of its name ranks above one where a word only starts a word of the name, then one where it is a word of the menu that holds it, then of its id, then text inside a word, so a query that is a menu's title ("object") lists results named with that word above the items of that menu. A tool ranks above a menu command, panel, effect or filter plug-in that matches as well, so "rect" lists the Rectangle Tool above Effect › Convert to Shape › Rectangle…, and of two results of the same kind the shorter name comes first. Words of the menu bar item that runs a result also find it, the item's own label included ("exit" finds Quit VectorCraft, which File › Exit runs); with the native macOS menu bar, the items that bar moves into its application menu are found under it (Preferences… under Settings). Every result the earlier search found is still found, and the highlight stays on its result when a plug-in is installed, a shortcut changes or the language changes while the palette is open (`palette::search` tests `a_better_word_grade_ranks_first`, `a_better_whole_query_tier_ranks_first`, `kind_and_length_never_lift_a_worse_grade`, `a_menu_title_does_not_lift_its_items`, `common_queries_list_the_command_near_the_top`, `every_result_is_found_first_by_its_name_and_its_id`, `every_result_found_before_is_still_found_and_shown`, `results_know_their_place_in_the_menu_bar`, `native_homes_follow_the_native_application_menu`; `palette` test `the_highlight_stays_on_its_result_when_the_results_change`). `object.setProps` with `visible: false` or `locked: true` deselects every selected object that is then hidden or locked, the key object included, as the eye and lock columns do. Ctrl/Cmd+Alt-clicking an eye switches the other layers to Outline and the row's layer to Preview, or switches all layers back to Preview when the others are in Outline (`layer.outlineOthers`, `layer.previewAll`).