diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 750e484b77..53bc91100b 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -513,6 +513,13 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let screen = ctx.content_rect(); // The highlighted result the rows and the field's description are drawn with. let mut drawn = sel; + // The backdrop covers the canvas, the toolbars, the docked panels and the app bar under the + // popup, in the order of a modal dialog's backdrop (`dialogs::modal::backdrop`), so the press + // that closes the palette does not press a control under it. Windows in the Foreground order + // stay above it. Not focusable (`Sense::click()` is): Tab stays in the popup. + egui::Area::new(egui::Id::unique("palette-backdrop")).order(egui::Order::Middle).fixed_pos(screen.min).show(ctx, |ui| { + ui.allocate_rect(screen, egui::Sense::CLICK); + }); // The area keeps itself inside the window (egui's `Area::constrain` is on), so in a window too // short for the field, one row and the footer below TOP, the popup moves up. egui::Area::new(egui::Id::unique("palette")).order(egui::Order::Foreground).anchor(egui::Align2::CENTER_TOP, [0.0, TOP]).show(ctx, |ui| { @@ -603,6 +610,20 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } }); }); + // A press of any pointer button that the popup's layer does not get closes it: a press on the + // backdrop, or on a window above it, which also gets the press, even where that window lies + // over the popup. + let presses: Vec = ctx.input(|i| { + i.events + .iter() + .filter_map(|e| match e { + egui::Event::PointerButton { pos, pressed: true, .. } => Some(*pos), + _ => None, + }) + .collect() + }); + let popup = egui::LayerId::new(egui::Order::Foreground, egui::Id::unique("palette")); + let outside = presses.into_iter().any(|p| ctx.layer_id_at(p) != Some(popup)); // The pointer or a scroll moved the highlight after the rows were drawn: the next frame draws // it where it now is. if sel != drawn { @@ -612,6 +633,8 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { if let Some(id) = run { app.ui.palette_open = false; run_pick(app, &id); + } else if outside { + app.ui.palette_open = false; } } @@ -1788,4 +1811,220 @@ mod tests { frame(&mut app, false); assert_ne!(ctx.memory(|m| m.focused()), Some(field), "the dialog keeps the focus"); } + + /// The whole window, with a document whose rectangle is selected, drawn a frame at a time in + /// English with screen readers on. + struct Window { + app: VectorcraftApp, + ctx: egui::Context, + time: f64, + /// Draw a window with an "Above" button at this place, in the Foreground order after the + /// app, as a progress window is drawn, and count its clicks. + above: Option, + above_clicks: usize, + } + + impl Window { + fn new() -> Window { + crate::i18n::set_current(Lang::EN); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap(); + 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 }; + window.frame(vec![]); + window.frame(vec![]); + window + } + + /// One frame of the whole window with `events`: its screen-reader tree. + fn frame(&mut self, events: Vec) -> Vec { + self.time += 0.1; + 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 mut out = self.ctx.run_ui(input, |ui| { + app.logic(ui.ctx()); + 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); + area.show(ui.ctx(), |ui| { + if ui.button("Above").clicked() { + *clicks += 1; + } + }); + } + }); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes.into_iter().map(|(_, n)| n).collect()).unwrap_or_default() + } + + /// A primary click at `at`, a frame for the move, the press and the release: the release + /// frame's screen-reader tree. + fn click(&mut self, at: egui::Pos2) -> Vec { + let button = + |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + self.frame(vec![egui::Event::PointerMoved(at)]); + self.frame(vec![button(true)]); + self.frame(vec![button(false)]) + } + + /// A press of `button` at `from`, a move to `to` and the release there, a frame each. + fn drag(&mut self, button: egui::PointerButton, from: egui::Pos2, to: egui::Pos2) { + let event = |pos, pressed| egui::Event::PointerButton { pos, button, pressed, modifiers: egui::Modifiers::NONE }; + self.frame(vec![egui::Event::PointerMoved(from)]); + self.frame(vec![event(from, true)]); + self.frame(vec![egui::Event::PointerMoved(to)]); + self.frame(vec![event(to, false)]); + } + + fn selection(&self) -> String { + format!("{:?}", self.app.session.doc().unwrap().selection) + } + + fn popup(&self) -> egui::Rect { + self.ctx.memory(|m| m.area_rect(egui::Id::unique("palette"))).unwrap() + } + } + + /// The middle of the button whose screen-reader name is `name`, alone or followed by its + /// shortcut in parentheses. + fn button_at(nodes: &[egui::accesskit::Node], name: &str) -> egui::Pos2 { + let names: Vec<_> = nodes.iter().filter(|n| n.role() == egui::accesskit::Role::Button).filter_map(|n| n.label()).collect(); + let named = |l: &str| l == name || l.strip_prefix(name).is_some_and(|rest| rest.starts_with(' ') && rest.trim_start().starts_with('(')); + let node = nodes + .iter() + .find(|n| n.role() == egui::accesskit::Role::Button && n.label().is_some_and(named)) + .unwrap_or_else(|| panic!("a button named {name}: {names:?}")); + let b = node.bounds().unwrap(); + egui::pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32) + } + + /// A click on the canvas outside the popup closes it and leaves the selection as it was. + #[test] + fn a_click_on_the_canvas_closes_the_palette() { + let mut window = Window::new(); + let before = window.selection(); + window.app.ui.palette_open = true; + window.frame(vec![]); + let canvas = window.app.canvas_rect.expect("the canvas is drawn"); + let at = canvas.left_bottom() + egui::vec2(30.0, -30.0); + assert!(!window.popup().contains(at), "{at:?} is outside {:?}", window.popup()); + window.click(at); + assert!(!window.app.ui.palette_open, "the click outside closes the palette"); + window.frame(vec![]); + assert_eq!(window.selection(), before, "the click does not reach the canvas"); + } + + /// A click on another control outside the popup closes the popup and does not press the + /// control. + #[test] + fn a_click_on_another_control_closes_the_palette_without_pressing_it() { + let mut window = Window::new(); + let tool = window.app.session.tool_id(); + window.app.ui.palette_open = true; + let nodes = window.frame(vec![]); + let at = button_at(&nodes, "Pen Tool"); + assert!(!window.popup().contains(at), "{at:?} is outside {:?}", window.popup()); + window.click(at); + assert!(!window.app.ui.palette_open, "the click outside closes the palette"); + window.frame(vec![]); + assert_eq!(window.app.session.tool_id(), tool, "the click does not pick the tool"); + // With the palette closed, the same click picks it. + window.click(at); + assert_eq!(window.app.session.tool_id(), "pen"); + } + + /// A right-click outside the popup closes it, and so does a drag that starts outside it. + #[test] + fn a_right_click_or_a_drag_outside_closes_the_palette() { + let mut window = Window::new(); + let before = window.selection(); + let canvas = window.app.canvas_rect.expect("the canvas is drawn"); + let at = canvas.left_bottom() + egui::vec2(30.0, -30.0); + window.app.ui.palette_open = true; + window.frame(vec![]); + assert!(!window.popup().contains(at), "{at:?} is outside {:?}", window.popup()); + window.drag(egui::PointerButton::Secondary, at, at); + assert!(!window.app.ui.palette_open, "the right-click outside closes the palette"); + window.app.ui.palette_open = true; + window.frame(vec![]); + window.drag(egui::PointerButton::Primary, at, at + egui::vec2(80.0, -60.0)); + assert!(!window.app.ui.palette_open, "the drag outside closes the palette"); + window.frame(vec![]); + assert_eq!(window.selection(), before, "the drag does not reach the canvas"); + } + + /// A click on a window drawn above the backdrop, as a progress window is, closes the palette + /// and presses that window's button, beside the popup and where the window lies over it. + #[test] + fn a_click_on_a_window_above_closes_the_palette_and_reaches_it() { + for over in [false, true] { + let mut window = Window::new(); + window.app.ui.palette_open = true; + window.frame(vec![]); + let popup = window.popup(); + window.above = Some(if over { popup.center() } else { egui::pos2(40.0, 400.0) }); + window.frame(vec![]); + let nodes = window.frame(vec![]); + let at = button_at(&nodes, "Above"); + assert_eq!(popup.contains(at), over, "{at:?} and the popup {popup:?}"); + window.click(at); + assert!(!window.app.ui.palette_open, "over the popup: {over}; the click on the window closes the palette"); + assert_eq!(window.above_clicks, 1, "over the popup: {over}; the window gets the click"); + } + } + + /// The click on the app bar's search button that opens the palette leaves it open; the next + /// click on the button closes it. + #[test] + fn the_click_that_opens_the_palette_does_not_close_it() { + let mut window = Window::new(); + let nodes = window.frame(vec![]); + let at = button_at(&nodes, "Search commands, tools, panels and effects"); + window.click(at); + assert!(window.app.ui.palette_open, "the click opens the palette"); + window.frame(vec![]); + window.frame(vec![]); + assert!(window.app.ui.palette_open, "and it stays open"); + window.click(at); + assert!(!window.app.ui.palette_open, "a second click closes it"); + } + + /// Clicks inside the popup keep it open: one in the search field, and one on a result, which + /// runs that result. + #[test] + fn clicks_inside_the_palette_keep_it_or_run_a_result() { + let mut window = Window::new(); + window.app.ui.palette_open = true; + window.app.ui.palette_query = "show panel".into(); + window.frame(vec![]); + let nodes = window.frame(vec![]); + let popup = window.popup(); + let middle = |b: egui::accesskit::Rect| egui::pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32); + let field = nodes + .iter() + .filter(|n| n.role() == egui::accesskit::Role::TextInput) + .filter_map(|n| n.bounds().map(middle)) + .find(|p| popup.contains(*p)) + .expect("the search field"); + window.click(field); + window.frame(vec![]); + assert!(window.app.ui.palette_open, "a click in the field keeps the palette open"); + assert_eq!(window.app.ui.palette_query, "show panel"); + let nodes = window.frame(vec![]); + let entries = entries(&window.ctx, Lang::EN); + let listed: Vec<_> = matching(&entries, "show panel").into_iter().take(MAX_RESULTS).collect(); + let hidden = |e: &&&Entry| e.id.strip_prefix("panel:").is_some_and(|p| !crate::panel_docking::showing(&window.app.ui, p)); + let e = listed.iter().find(hidden).expect("a hidden panel's result"); + let label = row_label(e); + let row = rows(&nodes).into_iter().find(|r| r.0 == label).expect("its row is drawn"); + let panel = e.id.strip_prefix("panel:").unwrap_or_default().to_string(); + window.click(egui::pos2(window.popup().center().x, ((row.2 + row.3) / 2.0) as f32)); + assert!(!window.app.ui.palette_open); + assert!(crate::panel_docking::showing(&window.app.ui, &panel), "{panel}: {}", window.app.ui.status); + } } diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 9b50129f41..fbca583b89 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1255,6 +1255,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur No two Command Palette results for different commands, tools or plug-ins show the same name, in English or in any language with a complete menu catalog. Results that would share a name show the panel, menu or command they belong to (Export › Continue in Background and Open › Continue in Background, View › Rulers › Show Rulers and View › Perspective Grid › Show Rulers, Layers › Panel Options… and Navigator › Panel Options…, Tools › Knife and Path › Knife); results that still share one show their id after it (Ellipse (shape.ellipse) and Ellipse (addon.shapes.ellipse)), as two filter plug-ins with one name do. A query still finds a result by its name without the added path. Batch…, Flattener Preview and the four Other Library… commands are listed once each as their UI command, and Place… and Print… once each (`palette` tests `different_results_show_different_names`, `results_that_share_a_name_show_where_they_belong`, `filter_plugins_with_one_name_show_their_ids`, `each_id_is_one_result`, `a_pick_of_a_renamed_result_runs_its_own_command`). 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. Results whose name without its menu path is the whole query come first, so "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`). `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`). Ctrl/Cmd+Alt-clicking New Layer adds a layer directly below the current layer, at its level (`layer.new {below: true}`), and Ctrl/Cmd+Alt-clicking New Sublayer adds a sublayer under the contents of the layer it goes into (`layer.newSublayer {bottom: true}`), each in one undo step. The reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists these clicks for placing a layer below the selected layer and a new sublayer at the bottom of the layer list.