From 241fec357956b9f9d19b9b51ffda7a563adeb1ce Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 09:21:53 -0800 Subject: [PATCH 1/6] Command Palette: commands that cannot run now are dimmed A result that cannot run now stays in its place in the list and is drawn in the disabled text color: an engine command whose engine check fails (Ungroup with nothing selected, Paste with an empty clipboard and nothing to paste from the system clipboard), a UI command the menus dim, a filter plug-in or an effect whose menu item is dimmed, and a panel in Presentation Mode. Tools are never dimmed. The engine's reason, or that the command is not available right now, shows on hover, as the row's screen-reader description, and in the footer while the row is highlighted: beside the count, or on a line of its own under the recent picks of an empty search. The row's screen-reader node is marked disabled. Both messages are existing status messages, so no catalog changes. Only the drawn rows are checked, each once per state: the key is what the native menu bar's rows depend on (native_menu::state_hash, now pub(crate)), plus unsaved changes, the screen mode, an open dialog and background saves, exports, file reads, plug-in runs and traces, and a frame with a click. Typing in the search field keeps the answers. One engine check took 102 ms on a 20,000-object selection in a release build. The check does not change the ranking, and a pick of a dimmed result does what it did before. --- crates/ui-egui/src/native_menu.rs | 2 +- crates/ui-egui/src/palette.rs | 272 +++++++++++++++++++++++++++++- docs/target-app-parity.md | 1 + 3 files changed, 268 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/native_menu.rs b/crates/ui-egui/src/native_menu.rs index 510131be0e..40ebc46ba5 100644 --- a/crates/ui-egui/src/native_menu.rs +++ b/crates/ui-egui/src/native_menu.rs @@ -610,7 +610,7 @@ pub fn sync(app: &mut VectorcraftApp, ctx: &egui::Context) { /// interaction is open (for example a move, scale or shape drag, a dialog's or the font menu's /// preview, or a typing session), the revision, which each of its previews changes, is left out: /// the hash changes as the interaction begins and as it ends. -fn state_hash(app: &VectorcraftApp, input: Option) -> u64 { +pub(crate) fn state_hash(app: &VectorcraftApp, input: Option) -> u64 { let mut h = DefaultHasher::new(); input.hash(&mut h); app.run_count.hash(&mut h); diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index dbd19f3f57..6f6acb5643 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -437,6 +437,73 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { } } +/// Why the result `id` can't run now, as an English status message, or `None` while it can: the +/// engine's reason when it gives one, else the status line a dimmed menu item's pick gives +/// ([`crate::shortcut_editor::dimmed`]). A panel can't be shown in Presentation Mode, a tool can +/// always be chosen, and every other result asks [`menus::enabled`] about the command its pick +/// runs. +fn unavailable(app: &VectorcraftApp, id: &str) -> Option { + if id.starts_with("tool:") { + return None; + } + if id.starts_with("panel:") && app.ui.screen_mode >= 3 { + return Some("panels can't be shown in Presentation Mode".to_string()); + } + // The command the pick runs. + let id = if id.starts_with("panel:") || id.starts_with("plugin:") || id.starts_with("effect:") { + crate::keymap::command_of(id).id + } else { + id.to_string() + }; + if menus::enabled(app, &id) { + return None; + } + let why = vectorcraft_engine::find_command(&id).and_then(|c| (c.enabled)(&app.session).err()); + Some(why.unwrap_or_else(|| format!("command `{id}` is not available right now"))) +} + +/// The drawn results' [`unavailable`] answers, in the interface language, for the state `key` +/// ([`availability_key`]) they were read in. An engine check can take tens of milliseconds on a +/// large selection, so each result is asked once per state instead of on every frame. +#[derive(Clone, Default)] +struct Availability { + key: u64, + known: std::collections::HashMap>, +} + +impl Availability { + /// Why the result `id` can't run now, translated, or `None` while it can. + fn why(&mut self, app: &VectorcraftApp, id: &str) -> Option { + if let Some(why) = self.known.get(id) { + return why.clone(); + } + let why = unavailable(app, id).map(|why| crate::i18n::msg(&why)); + self.known.insert(id.to_string(), why.clone()); + why + } +} + +/// What the results' availability depends on: what the native menu bar's rows depend on +/// ([`crate::native_menu::state_hash`]: commands run, the document's revision, selection, history +/// and clipboard, the language and more), whether the document has unsaved changes, the screen +/// mode, an open dialog, and the background saves and exports, file reads, plug-in runs and traces +/// that run or show their progress. A frame with a pointer button release also changes it, for +/// what it leaves out (a panel shown, a tool chosen); typing in the search field does not. +fn availability_key(app: &VectorcraftApp, ctx: &egui::Context) -> u64 { + use std::hash::{Hash, Hasher}; + let click = ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { pressed: false, .. }))); + let mut h = std::collections::hash_map::DefaultHasher::new(); + crate::native_menu::state_hash(app, click.then_some(app.host_iteration)).hash(&mut h); + let running = app.background.jobs.iter().filter(|j| j.progress.is_some() && !j.cancelled()).count(); + (app.ui.screen_mode, app.ui.dialog.is_some(), app.background.jobs.len(), running).hash(&mut h); + (app.opening.pending.len(), crate::opening::any_shown(app)).hash(&mut h); + // A background save marks the document saved without a new revision. + app.session.active().map(|d| (d.path.is_some(), d.converted, d.is_dirty())).hash(&mut h); + let plugins = (crate::plugin_runs::any_running(app), crate::plugin_runs::any_shown(app)); + (plugins, crate::trace_runs::any_running(app), crate::trace_runs::any_shown(app)).hash(&mut h); + h.finish() +} + /// The entries the query `q` matches, best first ([`search::rank`]), with the commands picked most /// often (`uses`) first among the entries that match as well, and then the picks that Recent /// Commands lists for the ids `recent_ids` ([`recent`]). The ranking of the last query is kept, so @@ -788,6 +855,13 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { }); } let screen = ctx.content_rect(); + // The drawn results' availability, kept while the state it was read in lasts. + let availability_id = egui::Id::unique("palette-availability"); + let key = availability_key(app, ctx); + let mut availability = ctx + .data_mut(|d| d.remove_temp::(availability_id)) + .filter(|a| a.key == key) + .unwrap_or(Availability { key, known: Default::default() }); // 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 @@ -884,19 +958,32 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { if on { ui.painter().rect_filled(rect, 4.0, ui.visuals().selection.bg_fill); } + // A result that can't run now stays in its place, drawn dimmed, and says + // why on hover and to screen readers. + let why = availability.why(app, &e.id); + let (name_color, shortcut_color) = if why.is_some() { (t.text_disabled, t.text_disabled) } else { (t.text, t.text_dim) }; let font = egui::TextStyle::Body.resolve(ui.style()); let shortcut = menus::shown_shortcut(&e.shortcut); let p = ui.painter(); let shortcut_at = rect.right_center() - egui::vec2(8.0, 0.0); - let used = p.text(shortcut_at, egui::Align2::RIGHT_CENTER, &shortcut, font.clone(), t.text_dim); + let used = p.text(shortcut_at, egui::Align2::RIGHT_CENTER, &shortcut, font.clone(), shortcut_color); let name_end = if shortcut.is_empty() { rect.right() - 8.0 } else { used.left() - 12.0 }; let name_at = rect.left() + 8.0; - let name = name_galley(p, &e.shown, font, t.text, name_end - name_at); - p.galley(egui::pos2(name_at, rect.center().y - name.size().y / 2.0), name, t.text); + let name = name_galley(p, &e.shown, font, name_color, name_end - name_at); + p.galley(egui::pos2(name_at, rect.center().y - name.size().y / 2.0), name, name_color); // `WidgetInfo::selected` reaches screen readers as a toggled state, so the // row sets the selected state on its node itself. - resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ListItem, true, row_label(e))); - ui.ctx().accesskit_node_builder(resp.id, |node| node.set_selected(on)); + resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ListItem, why.is_none(), row_label(e))); + ui.ctx().accesskit_node_builder(resp.id, |node| { + node.set_selected(on); + if let Some(why) = &why { + node.set_description(why.clone()); + } + }); + let resp = match why { + Some(why) => resp.on_hover_text(why), + None => resp, + }; if resp.clicked() { run = Some(e.id.clone()); } @@ -911,10 +998,23 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } }); } + // While the highlighted result can't run now, the footer also says why, so a keyboard + // user reads it too: on the count's line, or alone under the recent picks, so the + // footer stays the height counted above. + let why = matches.get(sel).and_then(|e| availability.why(app, &e.id)); // Under the recent picks no count is shown; with none, one dimmed line says so. if !empty { ui.add_space(6.0); - ui.label(egui::RichText::new(footer(n, total)).color(t.text_dim)); + let count = ui.label(egui::RichText::new(footer(n, total)).color(t.text_dim)); + if let Some(why) = why { + let right = ui.max_rect().right(); + let at = egui::Rect::from_x_y_ranges((count.rect.right() + 12.0).min(right)..=right, count.rect.y_range()); + let why = egui::RichText::new(why).color(t.text_dim); + ui.put(at, egui::Label::new(why).truncate().halign(egui::Align::Max)); + } + } else if let Some(why) = why { + ui.add_space(6.0); + ui.add(egui::Label::new(egui::RichText::new(why).color(t.text_dim)).truncate()); } else if n == 0 { ui.label(egui::RichText::new(tl!("No recent commands")).color(t.text_dim)); } @@ -951,6 +1051,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { ctx.data_mut(|d| { d.insert_temp::(sel_id, (sel, q, offset, view, sel_key)); d.insert_temp(rsel_id, rsel); + d.insert_temp(availability_id, availability); }); if let Some(id) = run { app.ui.palette_open = false; @@ -2621,6 +2722,165 @@ mod tests { assert!(crate::panel_docking::showing(&open.app.ui, &panel), "{panel}: {}", open.app.ui.status); } + /// The open palette on `query` over the session `session`. + fn open_on(query: &str, session: vectorcraft_engine::Session) -> Open { + let mut open = Open::new(query, WINDOW); + open.app = VectorcraftApp::new(session, crate::Services::default()); + open.app.ui.palette_open = true; + open.app.ui.palette_query = query.into(); + open.frame(vec![]); + open + } + + /// The screen-reader node of the result row named `name`. + fn row_named<'a>(nodes: &'a [egui::accesskit::Node], name: &str) -> &'a egui::accesskit::Node { + nodes + .iter() + .filter(|n| n.role() == egui::accesskit::Role::ListItem) + .find(|n| n.label().is_some_and(|l| l == name || l.starts_with(&format!("{name}, ")))) + .unwrap_or_else(|| panic!("a row named {name}: {:?}", rows(nodes))) + } + + /// Highlights the result `id` with the arrow keys: the frame's screen-reader tree. + fn highlight(open: &mut Open, id: &str) -> Vec { + let k = open.listed().iter().position(|e| e == id).unwrap_or_else(|| panic!("{id} is listed")); + assert!(k < VISIBLE_ROWS, "{:?}", open.listed()); + let nodes = open.press(egui::Key::ArrowDown, k); + assert_eq!(open.highlighted(), k); + nodes + } + + /// With nothing selected, Ungroup stays listed in its place, dimmed, with the engine's reason in + /// its screen-reader description and in the footer while it is highlighted. Selecting art while + /// the palette stays open shows it as available on the next frame, in the same order. (A query + /// other tests' plug-in names do not match, so the list stays the same between frames.) + #[test] + fn a_result_that_cannot_run_now_is_dimmed_and_says_why() { + let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); + session.execute("select.none", &json!({})).unwrap(); + let why = crate::i18n::msg(&(vectorcraft_engine::find_command("object.ungroup").unwrap().enabled)(&session).unwrap_err()); + let mut open = open_on("ungroup", session); + let name = entries(&open.ctx, Lang::EN).iter().find(|e| e.id == "object.ungroup").map(row_label).unwrap(); + let order = open.listed(); + let nodes = highlight(&mut open, "object.ungroup"); + let ungroup = row_named(&nodes, &name); + assert!(ungroup.is_disabled(), "{ungroup:?}"); + assert_eq!(ungroup.description(), Some(why.as_str())); + let footer_says = |nodes: &[egui::accesskit::Node]| labels(nodes).contains(&why); + assert!(footer_says(&nodes), "{:?}", labels(&nodes)); + let dimmed_rows: Vec = rows(&nodes).into_iter().map(|r| r.0).collect(); + + open.app.run("select.all", json!({})).unwrap(); + let nodes = open.frame(vec![]); + let ungroup = row_named(&nodes, &name); + assert!(!ungroup.is_disabled() && ungroup.description().is_none(), "{ungroup:?}"); + assert!(!footer_says(&nodes), "{:?}", labels(&nodes)); + // Whether a result can run never moves it. + assert_eq!(open.listed(), order); + assert_eq!(rows(&nodes).into_iter().map(|r| r.0).collect::>(), dimmed_rows); + } + + /// Under an empty search, a highlighted recent pick that can't run now is dimmed and the line + /// under the picks says why. + #[test] + fn a_recent_pick_that_cannot_run_now_says_why() { + let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); + session.execute("select.none", &json!({})).unwrap(); + let why = crate::i18n::msg(&(vectorcraft_engine::find_command("object.ungroup").unwrap().enabled)(&session).unwrap_err()); + let mut open = open_on("", session); + open.app.ui.recent_commands = vec!["object.ungroup".to_string(), "object.group".to_string()]; + let nodes = open.frame(vec![]); + assert_eq!(open.highlighted(), 0); + let rows: Vec<_> = nodes.iter().filter(|n| n.role() == egui::accesskit::Role::ListItem).collect(); + assert_eq!(rows.len(), 2, "{rows:?}"); + assert!(rows.iter().all(|n| n.is_disabled()), "{rows:?}"); + assert!(labels(&nodes).contains(&why), "{:?}", labels(&nodes)); + let popup = open.popup(); + assert!(popup.bottom() <= WINDOW.y, "{popup:?}"); + } + + /// The drawn results are asked whether they can run once per state: keys pressed in the palette + /// keep the answers, and a command run or a click asks again. + #[test] + fn availability_is_read_once_per_state() { + let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); + session.execute("select.none", &json!({})).unwrap(); + let mut open = open_on("ungroup", session); + let id = egui::Id::unique("palette-availability"); + let read = |open: &Open| open.ctx.data(|d| d.get_temp::(id)).expect("the availability is kept"); + let first = read(&open); + assert!(first.known.get("object.ungroup").is_some_and(Option::is_some), "{:?}", first.known); + // The key also takes in state shared by every test (the language, the loaded fonts, the + // installed plug-ins), which other tests change at the same time, so the presses are tried + // again until one try keeps the key. + let kept = (0..20).any(|_| { + open.frame(vec![]); + let before = read(&open).key; + open.press(egui::Key::ArrowDown, 1); + open.press(egui::Key::X, 1); + read(&open).key == before + }); + assert!(kept, "key presses keep the answers"); + let first = read(&open); + open.app.run("select.all", json!({})).unwrap(); + open.frame(vec![]); + let after = read(&open); + assert_ne!(after.key, first.key); + assert_eq!(after.known.get("object.ungroup"), Some(&None), "asked again: {:?}", after.known); + let release = egui::Event::PointerButton { + pos: egui::pos2(1.0, 1.0), + button: egui::PointerButton::Primary, + pressed: false, + modifiers: egui::Modifiers::NONE, + }; + open.frame(vec![release]); + assert_ne!(read(&open).key, after.key, "a click asks again"); + } + + /// Paste is dimmed while the clipboard is empty and nothing can be pasted from the system + /// clipboard, and not while the system clipboard can be pasted. + #[test] + fn paste_is_dimmed_only_while_nothing_can_be_pasted() { + let mut open = open_on("paste", vectorcraft_testkit::fixtures::Fixture::Multi.session()); + open.app.system_paste = false; + let nodes = open.frame(vec![]); + let paste = row_named(&nodes, "Edit › Paste"); + assert!(paste.is_disabled(), "{paste:?}"); + assert_eq!(paste.description(), Some(crate::i18n::msg("clipboard is empty").as_str())); + open.app.system_paste = true; + let nodes = open.frame(vec![]); + assert!(!row_named(&nodes, "Edit › Paste").is_disabled()); + } + + /// A tool can always be chosen; a panel can't be shown in Presentation Mode, and says so. + #[test] + fn tools_are_never_dimmed_and_panels_are_in_presentation_mode() { + let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let tools: Vec = build(Lang::EN).into_iter().map(|e| e.id).filter(|id| id.starts_with("tool:")).collect(); + assert!(!tools.is_empty()); + assert!(tools.iter().all(|id| unavailable(&app, id).is_none()), "{tools:?}"); + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + assert_eq!(unavailable(&app, "panel:layers"), None); + app.ui.screen_mode = 3; + assert_eq!(unavailable(&app, "panel:layers").as_deref(), Some("panels can't be shown in Presentation Mode")); + } + + /// A UI command without an engine reason says it is not available, and a filter plug-in or an + /// effect asks about the command its pick runs. + #[test] + fn a_result_without_an_engine_reason_says_it_is_not_available() { + let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + assert!(vectorcraft_engine::find_command("ui.newBrush").is_none()); + assert_eq!(unavailable(&app, "ui.newBrush").as_deref(), Some("command `ui.newBrush` is not available right now")); + assert_eq!(unavailable(&app, "plugin:any.filter").as_deref(), Some("command `plugin.dialog` is not available right now")); + let effect = crate::shortcut_editor::effect_items().first().map(|e| format!("effect:{}", e.effect)).expect("an Effect menu item"); + assert!(unavailable(&app, &effect).is_some(), "{effect}"); + let app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + assert_eq!(unavailable(&app, "ui.newBrush"), None); + assert_eq!(unavailable(&app, "plugin:any.filter"), None); + assert_eq!(unavailable(&app, &effect), None, "{effect}"); + } + /// Screen readers stay on the field: its description names the highlighted result and its /// place, and follows the highlight; the rows are list items, the highlighted one selected, and /// the footer's count is a label. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 5fc911bc7a..4a1d5c828e 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1312,6 +1312,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur The Command Palette ranks the commands listed in Recent Commands first among the results that match a query as well as they do, the most recent first, and below every result that matches it better: after a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, so Enter runs it again. A recent pick ranks after the whole-query match, the word grades and the matches through a typo, a description or a word with the same meaning, and before the kind of result and the name's length. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. This is VectorCraft's own behavior (`palette::search` test `a_recent_pick_ranks_first_within_its_grades`; `palette` tests `a_recent_pick_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_recent_picks`). The Command Palette also counts how many times each command is picked and ranks the commands picked most often first among the results that match a query as well as they do, also after they leave Recent Commands, and below every result that matches it better. Counts are compared in grades that double: grade 1 starts at 1 pick, grade 2 at 3, grade 3 at 7, and so on up to grade 9, and a command picked once ranks above the commands never picked. The grade ranks after the word grades and the typo, description and same-meaning matches, and before the place among the recent picks. The count is kept for at most 200 commands: a new command then removes the one with the fewest picks, of those the one picked longest ago. When a count reaches 1,000, every count is halved and commands left at 0 are dropped. The counts are saved with the other interface settings (`command_uses` in `ui.json`); a count above 999 loads as 999 and an unreadable entry is dropped. The web build keeps them for the session. This is VectorCraft's own behavior (`palette::search` test `a_command_picked_often_ranks_first_within_its_grades`; `palette` tests `a_command_picked_often_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_pick_counts`, `a_count_does_not_pass_a_better_match`, `pick_counts_rank_in_grades_that_double`, `the_201st_command_removes_the_least_used_and_keeps_itself`, `counts_are_halved_at_one_thousand`, `saved_pick_counts_load_what_is_readable`). A Command Palette query word also finds a command by what the command's description says: "transparent background" lists Remove Background… among the first 3 results, and "png" lists it after every result with "png" in its name or menu path. The description is the command's params text (an engine or plug-in command's, a UI command's, or an effect's) without each `{…}` group that is not inside a `{`, `[` or `(` group, without each such `[…]` or `(…)` group just after a `→`, and without the `→` before a removed group, cut to its first 300 characters at the end of a word. The words of a schema ("corners" for Remove Background…) and of a result written as a group do not find the command; a result written as words after a `→` stays in the description. Words of 2 characters or fewer, words with no letter, and "the", "and", "ids", "true", "false" and "null" are left out. A query word that is a word of a description, shares an English base word with one, starts one or has the same meaning as one finds the result, and such a result ranks below every result that the query matches in its name, menu path or id, as text inside a word or through a typo. Descriptions are English only, and a typo does not match them. Tools, panels and filter plug-ins have no description (`palette::search` tests `a_description_leaves_out_the_schema_and_the_result`, `a_word_of_the_description_finds_the_result`, `a_description_match_ranks_below_a_typo`, `words_of_a_description_find_the_command`). + A Command Palette result that cannot run now stays in its place in the list and is drawn dimmed: an engine command whose engine check fails (Ungroup with nothing selected, Paste with an empty clipboard and nothing to paste from the system clipboard), a UI command the menus dim, a filter plug-in or an effect whose menu item is dimmed, and a panel in Presentation Mode. Tools are never dimmed. The engine's reason, or that the command is not available right now, shows on hover, in the row's screen-reader description and in the footer while the row is highlighted, beside the count or, under the recent picks of an empty search, on a line of its own. Only the drawn rows are checked, each once for as long as the state it was checked in lasts: a command run, an edit, a change of selection, document, history, clipboard, language, screen mode or open dialog, a save that marks the document saved, a background save, export, file read, plug-in run or trace that starts, ends or shows its progress window, or a click checks them again on the next frame, while typing in the search field does not. The check never changes the ranking. A pick of a dimmed result does what it did before (`palette` tests `a_result_that_cannot_run_now_is_dimmed_and_says_why`, `paste_is_dimmed_only_while_nothing_can_be_pasted`, `tools_are_never_dimmed_and_panels_are_in_presentation_mode`, `a_result_without_an_engine_reason_says_it_is_not_available`, `a_recent_pick_that_cannot_run_now_says_why`, `availability_is_read_once_per_state`). `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. From 2dcefa14e6d8dc0975b9fc4e07172faf5e485999 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 11:52:27 -0800 Subject: [PATCH 2/6] Command Palette: the search field's description says why the highlighted result can't run Arrow keys keep screen readers on the search field, so its description now adds the highlighted result's reason on a second line when the result can't run now. --- crates/ui-egui/src/palette.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 6f6acb5643..b702cf66e3 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -930,12 +930,16 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // keep the highlighted result in view. let resized = (view - last_view).abs() > 0.5; // Screen readers stay on the field: its description names the highlighted result and - // its place among every match, as the footer counts them. + // its place among every match, as the footer counts them, and on a second line why it + // can't run now when it can't. if let Some(e) = matches.get(sel) { let rank = if sel + 1 == matches.len() { kept.unwrap_or(sel) } else { sel }; let pos = (rank + 1).to_string(); let of = total.to_string(); - let said = crate::i18n::fmt(tl!("{pos} of {total}: {name}"), &[("pos", &pos), ("total", &of), ("name", &row_label(e))]); + let mut said = crate::i18n::fmt(tl!("{pos} of {total}: {name}"), &[("pos", &pos), ("total", &of), ("name", &row_label(e))]); + if let Some(why) = availability.why(app, &e.id) { + said = format!("{said}\n{why}"); + } ui.ctx().accesskit_node_builder(r.id, |node| node.set_description(said)); } if n > 0 { @@ -1648,7 +1652,7 @@ mod tests { assert_eq!(after.get(1).map(String::as_str), Some(tool), "only the pick moves"); let entries = entries(&open.ctx, Lang::EN); let label = entries.iter().find(|e| e.id == effect).map(row_label).unwrap(); - assert_eq!(field_description(&nodes), format!("1 of {}: {label}", after.len())); + assert_eq!(field_place(&nodes), format!("1 of {}: {label}", after.len())); open.press(egui::Key::Enter, 1); assert_eq!(open.app.ui.recent_commands, [effect], "Enter ran the effect again"); } @@ -2466,6 +2470,12 @@ mod tests { field.description().unwrap_or_default().to_string() } + /// The first line of the search field's description: the highlighted result's place and name, + /// without the reason a result that can't run now adds under it. + fn field_place(nodes: &[egui::accesskit::Node]) -> String { + field_description(nodes).lines().next().unwrap_or_default().to_string() + } + const WINDOW: egui::Vec2 = egui::vec2(1280.0, 900.0); /// Each result is a 20-point row, rows touch, and 12 show at once; the popup is shorter than @@ -2660,7 +2670,7 @@ mod tests { let lit: Vec = rows(&nodes).into_iter().filter(|r| r.1).map(|r| r.0).collect(); let label = entries.iter().find(|e| e.id == listed[3]).map(row_label).unwrap(); assert_eq!(lit, std::slice::from_ref(&label)); - assert_eq!(field_description(&nodes), format!("4 of {}: {label}", matching(&entries, "select", &[]).len())); + assert_eq!(field_place(&nodes), format!("4 of {}: {label}", matching(&entries, "select", &[]).len())); } /// A name too long for its row is cut short with "…" and stays inside the width it is given. @@ -2768,6 +2778,9 @@ mod tests { assert_eq!(ungroup.description(), Some(why.as_str())); let footer_says = |nodes: &[egui::accesskit::Node]| labels(nodes).contains(&why); assert!(footer_says(&nodes), "{:?}", labels(&nodes)); + // The arrow keys leave screen readers on the search field, so its description says why too. + let place = format!("{} of {}: {name}", open.highlighted() + 1, order.len()); + assert_eq!(field_description(&nodes), format!("{place}\n{why}")); let dimmed_rows: Vec = rows(&nodes).into_iter().map(|r| r.0).collect(); open.app.run("select.all", json!({})).unwrap(); @@ -2775,6 +2788,7 @@ mod tests { let ungroup = row_named(&nodes, &name); assert!(!ungroup.is_disabled() && ungroup.description().is_none(), "{ungroup:?}"); assert!(!footer_says(&nodes), "{:?}", labels(&nodes)); + assert_eq!(field_description(&nodes), place); // Whether a result can run never moves it. assert_eq!(open.listed(), order); assert_eq!(rows(&nodes).into_iter().map(|r| r.0).collect::>(), dimmed_rows); @@ -2894,19 +2908,19 @@ mod tests { // More results match than the list holds: the place counts every match, as the footer does. let total = matching(&entries, "show panel", &[]).len(); assert!(total > MAX_RESULTS && listed.len() == MAX_RESULTS, "{total}"); - assert_eq!(field_description(&nodes), format!("1 of {total}: {}", label(0))); + assert_eq!(field_place(&nodes), format!("1 of {total}: {}", label(0))); let lit: Vec = rows(&nodes).into_iter().filter(|r| r.1).map(|r| r.0).collect(); assert_eq!(lit, [label(0)]); assert!(labels(&nodes).contains(&format!("50 of {total} results. Keep typing to narrow them.")), "{:?}", labels(&nodes)); let nodes = open.press(egui::Key::ArrowDown, 1); - assert_eq!(field_description(&nodes), format!("2 of {total}: {}", label(1))); + assert_eq!(field_place(&nodes), format!("2 of {total}: {}", label(1))); // Fewer results match than the list holds. let mut open = Open::new("eyedropper", WINDOW); let n = open.listed().len(); assert!((1..MAX_RESULTS).contains(&n), "{n}"); let first = entries.iter().find(|e| e.id == open.listed()[0]).map(row_label).unwrap(); let nodes = open.frame(vec![]); - assert_eq!(field_description(&nodes), format!("1 of {n}: {first}")); + assert_eq!(field_place(&nodes), format!("1 of {n}: {first}")); assert!(labels(&nodes).contains(&footer(n, n)), "{:?}", labels(&nodes)); } @@ -3293,6 +3307,6 @@ mod tests { assert_eq!((sel, &now), (MAX_RESULTS - 1, &id), "the highlight stays on its result, in the last row"); let label = row_label(ranked[MAX_RESULTS]); assert!(rows(&nodes).iter().any(|r| r.1 && r.0 == label), "its row is drawn and highlighted"); - assert_eq!(field_description(&nodes), format!("{} of {}: {label}", MAX_RESULTS + 1, ranked.len())); + assert_eq!(field_place(&nodes), format!("{} of {}: {label}", MAX_RESULTS + 1, ranked.len())); } } From 3c9db048e014d9b1a176a9f606a0756227d6335b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 12:36:08 -0800 Subject: [PATCH 3/6] Command Palette: dimmed results name themselves, not their command id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A result's reason is the status line a pick of its dimmed menu item gives, with the result's name in place of the command id: "command `Object › Ungroup` is not available right now: nothing selected". `shortcut_editor::dimmed` builds it for both, so the hover reason and the pick's status line read alike. The reason is kept in English and translated when it is shown. - The engine's check of a dimmed engine command runs once: the new `menus::why_off` gives `menus::enabled`'s answer with the engine's reason. `menu_target_now` and the palette's effect picks use it too. - The Recent Commands list beside the search field draws a pick that can't run now dimmed, disabled for screen readers with the reason as its description, and with the reason on hover. - The palette drops its answers when it closes, so opening it again with the keyboard asks again. - A frame with a click asks again on that frame only: the click is no longer part of the key, so the next frame keeps the answers. --- crates/ui-egui/src/menus.rs | 1 + crates/ui-egui/src/menus/state.rs | 26 ++- crates/ui-egui/src/palette.rs | 303 +++++++++++++++++++++----- crates/ui-egui/src/shortcut_editor.rs | 36 ++- docs/target-app-parity.md | 2 +- 5 files changed, 294 insertions(+), 74 deletions(-) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 4e2d80bb45..2a0db30223 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -78,6 +78,7 @@ pub use run::{check_params, run_ui_command}; pub(crate) use run::{normalize_panel, opt_bool, opt_index, opt_number}; #[cfg(test)] use slots::RECENT_FONT_IDS; +pub(crate) use state::why_off; pub use state::{checked, enabled, plugin_revision, shortcut_of, shown_state}; pub(crate) use submenus::PATH_EFFECTS; pub use tree::{menu_tree, menu_tree_named}; diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index d4dda4698b..f22c79576b 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -200,22 +200,38 @@ pub(super) fn has_subject(app: &VectorcraftApp) -> bool { /// Can command `id` run now? An engine command asks the engine, a UI command the app's state; /// none that would act on text an input method is still composing. pub fn enabled(app: &VectorcraftApp, id: &str) -> bool { + why_off(app, id).is_none() +} + +/// Why command `id` can't run now ([`enabled`]): `None` while it can, else `Some` with the +/// engine's reason when the engine's check of an engine command fails. The engine's check runs at +/// most once. +pub(crate) fn why_off(app: &VectorcraftApp, id: &str) -> Option> { if waits_for_ime(app, id) { - return false; + return Some(None); } if SUBJECT_COMMANDS.contains(&id) { - return has_subject(app); + return (!has_subject(app)).then_some(None); } // The Artboard tool's canvas menu measured this when it opened. if id == "artboard.deleteEmpty" && let Some(facts) = crate::panels::artboards::open_menu_facts(app) { - return facts.any_empty; + return (!facts.any_empty).then_some(None); } if let Some(c) = vectorcraft_engine::find_command(id) { - // The system clipboard's contents can be pasted with an empty internal clipboard. - return (c.enabled)(&app.session).is_ok() || app.system_paste && id.starts_with("edit.paste"); + return match (c.enabled)(&app.session) { + Ok(()) => None, + // The system clipboard's contents can be pasted with an empty internal clipboard. + Err(_) if app.system_paste && id.starts_with("edit.paste") => None, + Err(why) => Some(Some(why)), + }; } + (!ui_enabled(app, id)).then_some(None) +} + +/// Can UI command `id` run now? +fn ui_enabled(app: &VectorcraftApp, id: &str) -> bool { match id { // Save is off for a clean document that already has its own file. "file.save" => app.session.active().is_some_and(|d| d.path.is_none() || d.converted || d.is_dirty()), diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index b702cf66e3..49338b0d2c 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -421,10 +421,10 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { let command = crate::keymap::command_of(id); // While the Effect menu dims the item (nothing selected), no dialog opens and the status // line says why. - if id.starts_with("effect:") && !menus::enabled(app, &command.id) { - if let Err(why) = crate::shortcut_editor::dimmed(app, &command.id) { - app.status(why); - } + if id.starts_with("effect:") + && let Some(why) = crate::shortcut_editor::dimmed(app, &command.id, &command.id) + { + app.status(why); } else { menus::invoke(app, &command.id, command.params); } @@ -437,12 +437,12 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { } } -/// Why the result `id` can't run now, as an English status message, or `None` while it can: the -/// engine's reason when it gives one, else the status line a dimmed menu item's pick gives -/// ([`crate::shortcut_editor::dimmed`]). A panel can't be shown in Presentation Mode, a tool can -/// always be chosen, and every other result asks [`menus::enabled`] about the command its pick -/// runs. -fn unavailable(app: &VectorcraftApp, id: &str) -> Option { +/// Why the result `id`, shown as `name`, can't run now, as an English status message, or `None` +/// while it can: the status line a pick of its dimmed menu item gives +/// ([`crate::shortcut_editor::dimmed`]), with the engine's reason when it gives one and `name` in +/// place of the command's id. A panel can't be shown in Presentation Mode, a tool can always be +/// chosen, and every other result asks about the command its pick runs. +fn unavailable(app: &VectorcraftApp, id: &str, name: &str) -> Option { if id.starts_with("tool:") { return None; } @@ -455,31 +455,38 @@ fn unavailable(app: &VectorcraftApp, id: &str) -> Option { } else { id.to_string() }; - if menus::enabled(app, &id) { - return None; - } - let why = vectorcraft_engine::find_command(&id).and_then(|c| (c.enabled)(&app.session).err()); - Some(why.unwrap_or_else(|| format!("command `{id}` is not available right now"))) + crate::shortcut_editor::dimmed(app, &id, name) } -/// The drawn results' [`unavailable`] answers, in the interface language, for the state `key` -/// ([`availability_key`]) they were read in. An engine check can take tens of milliseconds on a -/// large selection, so each result is asked once per state instead of on every frame. +/// The drawn results' [`unavailable`] answers for the state `key` ([`availability_key`]) they were +/// read in. An engine check can take tens of milliseconds on a large selection, so each result is +/// asked once per state instead of on every frame. #[derive(Clone, Default)] struct Availability { key: u64, + /// Each asked result's answer: why it can't run now, in English, or `None` while it can. known: std::collections::HashMap>, + /// How many results were asked since the key was set. + #[cfg(test)] + asked: usize, } impl Availability { - /// Why the result `id` can't run now, translated, or `None` while it can. - fn why(&mut self, app: &VectorcraftApp, id: &str) -> Option { - if let Some(why) = self.known.get(id) { - return why.clone(); - } - let why = unavailable(app, id).map(|why| crate::i18n::msg(&why)); - self.known.insert(id.to_string(), why.clone()); - why + /// Why the result `e` can't run now, in the interface language, or `None` while it can. + fn why(&mut self, app: &VectorcraftApp, e: &Entry) -> Option { + let why = match self.known.get(&e.id) { + Some(why) => why.clone(), + None => { + #[cfg(test)] + { + self.asked += 1; + } + let why = unavailable(app, &e.id, &e.shown); + self.known.insert(e.id.clone(), why.clone()); + why + } + }; + why.map(|why| crate::i18n::msg(&why)) } } @@ -487,13 +494,12 @@ impl Availability { /// ([`crate::native_menu::state_hash`]: commands run, the document's revision, selection, history /// and clipboard, the language and more), whether the document has unsaved changes, the screen /// mode, an open dialog, and the background saves and exports, file reads, plug-in runs and traces -/// that run or show their progress. A frame with a pointer button release also changes it, for -/// what it leaves out (a panel shown, a tool chosen); typing in the search field does not. -fn availability_key(app: &VectorcraftApp, ctx: &egui::Context) -> u64 { +/// that run or show their progress. A click asks again for what it leaves out (a panel shown, a +/// tool chosen) without changing it ([`show`]); typing in the search field does not. +fn availability_key(app: &VectorcraftApp) -> u64 { use std::hash::{Hash, Hasher}; - let click = ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { pressed: false, .. }))); let mut h = std::collections::hash_map::DefaultHasher::new(); - crate::native_menu::state_hash(app, click.then_some(app.host_iteration)).hash(&mut h); + crate::native_menu::state_hash(app, None).hash(&mut h); let running = app.background.jobs.iter().filter(|j| j.progress.is_some() && !j.cancelled()).count(); (app.ui.screen_mode, app.ui.dialog.is_some(), app.background.jobs.len(), running).hash(&mut h); (app.opening.pending.len(), crate::opening::any_shown(app)).hash(&mut h); @@ -752,11 +758,14 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let focus_id = egui::Id::unique("palette-focus-before"); let field_id = egui::Id::unique("palette-field"); let sel_id = egui::Id::unique("palette-selected"); + let availability_id = egui::Id::unique("palette-availability"); if !app.ui.palette_open { // The palette opens again with its first row highlighted and its list scrolled to the top - // (a list height of 0 scrolls it to the highlighted row). + // (a list height of 0 scrolls it to the highlighted row), and asks its results again + // whether they can run. let field = ctx.data_mut(|d| { d.remove::(sel_id); + d.remove::(availability_id); let field = d.get_temp::(field_id); d.remove::(field_id); field @@ -855,13 +864,16 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { }); } let screen = ctx.content_rect(); - // The drawn results' availability, kept while the state it was read in lasts. - let availability_id = egui::Id::unique("palette-availability"); - let key = availability_key(app, ctx); + // The drawn results' availability, kept while the state it was read in lasts. A frame with a + // pointer button release asks again, once, for what the state leaves out. + let key = availability_key(app); let mut availability = ctx .data_mut(|d| d.remove_temp::(availability_id)) .filter(|a| a.key == key) - .unwrap_or(Availability { key, known: Default::default() }); + .unwrap_or_else(|| Availability { key, ..Default::default() }); + if ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { pressed: false, .. }))) { + availability.known.clear(); + } // 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 @@ -900,7 +912,25 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { ui.add_enabled(false, egui::Button::new(tl!("No recent commands"))); } for (i, e) in recent.iter().enumerate() { - let row = ui.add(egui::Button::new(e.shown.as_str()).shortcut_text(menus::shown_shortcut(&e.shortcut))); + // A pick that can't run now is drawn dimmed, as in the results, and says + // why on hover and to screen readers; it can still be chosen. + let why = availability.why(app, e); + let (name, shortcut) = (egui::RichText::new(e.shown.as_str()), egui::RichText::new(menus::shown_shortcut(&e.shortcut))); + let (name, shortcut) = match why { + Some(_) => (name.color(t.text_disabled), shortcut.color(t.text_disabled)), + None => (name, shortcut), + }; + let row = ui.add(egui::Button::new(name).shortcut_text(shortcut)); + ui.ctx().accesskit_node_builder(row.id, |node| { + if let Some(why) = &why { + node.set_disabled(); + node.set_description(why.clone()); + } + }); + let row = match why { + Some(why) => row.on_hover_text(why), + None => row, + }; if i == rsel { row.request_focus(); } @@ -937,7 +967,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let pos = (rank + 1).to_string(); let of = total.to_string(); let mut said = crate::i18n::fmt(tl!("{pos} of {total}: {name}"), &[("pos", &pos), ("total", &of), ("name", &row_label(e))]); - if let Some(why) = availability.why(app, &e.id) { + if let Some(why) = availability.why(app, e) { said = format!("{said}\n{why}"); } ui.ctx().accesskit_node_builder(r.id, |node| node.set_description(said)); @@ -964,7 +994,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } // A result that can't run now stays in its place, drawn dimmed, and says // why on hover and to screen readers. - let why = availability.why(app, &e.id); + let why = availability.why(app, e); let (name_color, shortcut_color) = if why.is_some() { (t.text_disabled, t.text_disabled) } else { (t.text, t.text_dim) }; let font = egui::TextStyle::Body.resolve(ui.style()); let shortcut = menus::shown_shortcut(&e.shortcut); @@ -1005,7 +1035,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // While the highlighted result can't run now, the footer also says why, so a keyboard // user reads it too: on the count's line, or alone under the recent picks, so the // footer stays the height counted above. - let why = matches.get(sel).and_then(|e| availability.why(app, &e.id)); + let why = matches.get(sel).and_then(|e| availability.why(app, e)); // Under the recent picks no count is shown; with none, one dimmed line says so. if !empty { ui.add_space(6.0); @@ -2388,6 +2418,8 @@ mod tests { time: f64, /// Whether the last frame asked for another one at once. repaint: bool, + /// What the last frame drew. + shapes: Vec, } impl Open { @@ -2401,7 +2433,7 @@ mod tests { ctx.enable_accesskit(); crate::theme::install_fonts(&ctx); crate::theme::apply(&ctx, Default::default()); - let mut open = Open { app, ctx, size, time: 0.0, repaint: false }; + let mut open = Open { app, ctx, size, time: 0.0, repaint: false, shapes: Vec::new() }; open.frame(vec![]); open } @@ -2415,6 +2447,7 @@ mod tests { let mut out = self.ctx.run_ui(input, |ui| show(app, ui.ctx())); out.textures_delta.clear(); self.repaint = out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.repaint_delay.is_zero()); + self.shapes = std::mem::take(&mut out.shapes); out.platform_output.accesskit_update.map(|u| u.nodes.into_iter().map(|(_, n)| n).collect()).unwrap_or_default() } @@ -2424,6 +2457,18 @@ mod tests { self.frame(vec![key; times]) } + /// The color the last frame drew the text `text` in. + fn color_of(&self, text: &str) -> Option { + fn find(shape: &egui::Shape, text: &str) -> Option { + match shape { + egui::Shape::Text(t) if t.galley.text() == text => Some(t.fallback_color), + egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, text)), + _ => None, + } + } + self.shapes.iter().find_map(|s| find(&s.shape, text)) + } + /// The highlighted result's index. fn highlighted(&self) -> usize { self.ctx.data(|d| d.get_temp::(egui::Id::unique("palette-selected"))).unwrap().0 @@ -2768,14 +2813,18 @@ mod tests { fn a_result_that_cannot_run_now_is_dimmed_and_says_why() { let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); session.execute("select.none", &json!({})).unwrap(); - let why = crate::i18n::msg(&(vectorcraft_engine::find_command("object.ungroup").unwrap().enabled)(&session).unwrap_err()); + let why = ungroup_reason(&session); let mut open = open_on("ungroup", session); - let name = entries(&open.ctx, Lang::EN).iter().find(|e| e.id == "object.ungroup").map(row_label).unwrap(); + let entries = entries(&open.ctx, Lang::EN); + let entry = entries.iter().find(|e| e.id == "object.ungroup").unwrap(); + let name = row_label(entry); let order = open.listed(); let nodes = highlight(&mut open, "object.ungroup"); let ungroup = row_named(&nodes, &name); assert!(ungroup.is_disabled(), "{ungroup:?}"); assert_eq!(ungroup.description(), Some(why.as_str())); + let t = Tokens::get(&open.ctx); + assert_eq!(open.color_of(&entry.shown), Some(t.text_disabled), "the name is drawn dimmed"); let footer_says = |nodes: &[egui::accesskit::Node]| labels(nodes).contains(&why); assert!(footer_says(&nodes), "{:?}", labels(&nodes)); // The arrow keys leave screen readers on the search field, so its description says why too. @@ -2787,6 +2836,7 @@ mod tests { let nodes = open.frame(vec![]); let ungroup = row_named(&nodes, &name); assert!(!ungroup.is_disabled() && ungroup.description().is_none(), "{ungroup:?}"); + assert_eq!(open.color_of(&entry.shown), Some(t.text)); assert!(!footer_says(&nodes), "{:?}", labels(&nodes)); assert_eq!(field_description(&nodes), place); // Whether a result can run never moves it. @@ -2794,13 +2844,40 @@ mod tests { assert_eq!(rows(&nodes).into_iter().map(|r| r.0).collect::>(), dimmed_rows); } + /// Why Object › Ungroup can't run in `session`, as the palette shows it: the engine's reason, + /// with the result's name and no command id. + fn ungroup_reason(session: &vectorcraft_engine::Session) -> String { + let reason = (vectorcraft_engine::find_command("object.ungroup").unwrap().enabled)(session).unwrap_err(); + let why = crate::i18n::msg(&format!("command `Object › Ungroup` is not available right now: {reason}")); + assert!(!why.contains("object.ungroup"), "{why}"); + why + } + + /// The pointer resting on a result that can't run now shows why in a tooltip, as well as in + /// the footer of the result it highlights. + #[test] + fn hovering_a_result_that_cannot_run_now_says_why() { + let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); + session.execute("select.none", &json!({})).unwrap(); + let why = ungroup_reason(&session); + let mut open = open_on("ungroup", session); + let name = entries(&open.ctx, Lang::EN).iter().find(|e| e.id == "object.ungroup").map(row_label).unwrap(); + let nodes = open.frame(vec![]); + let b = row_named(&nodes, &name).bounds().unwrap(); + let at = egui::pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32); + open.frame(vec![egui::Event::PointerMoved(at)]); + let says = |nodes: &[egui::accesskit::Node]| labels(nodes).iter().filter(|l| **l == why).count(); + let shown = (0..30).map(|_| says(&open.frame(vec![]))).max().unwrap_or(0); + assert_eq!(shown, 2, "the footer and the tooltip"); + } + /// Under an empty search, a highlighted recent pick that can't run now is dimmed and the line /// under the picks says why. #[test] fn a_recent_pick_that_cannot_run_now_says_why() { let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); session.execute("select.none", &json!({})).unwrap(); - let why = crate::i18n::msg(&(vectorcraft_engine::find_command("object.ungroup").unwrap().enabled)(&session).unwrap_err()); + let why = ungroup_reason(&session); let mut open = open_on("", session); open.app.ui.recent_commands = vec!["object.ungroup".to_string(), "object.group".to_string()]; let nodes = open.frame(vec![]); @@ -2813,8 +2890,90 @@ mod tests { assert!(popup.bottom() <= WINDOW.y, "{popup:?}"); } + /// The Recent Commands list beside the search field draws a pick that can't run now dimmed, + /// disabled for screen readers with the reason as its description, and says why on hover. + #[test] + fn a_recent_command_that_cannot_run_now_is_dimmed_in_the_list() { + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + app.run("select.none", json!({})).unwrap(); + let why = ungroup_reason(&app.session); + app.ui.recent_commands = vec!["object.ungroup".into(), "select.all".into()]; + let mut h = palette_harness(app); + h.ctx.all_styles_mut(|s| s.interaction.tooltip_delay = 0.0); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + let shown = |id: &str| entries(&h.ctx, Lang::EN).iter().find(|e| e.id == id).map(|e| e.shown.clone()).unwrap(); + let (ungroup, all) = (shown("object.ungroup"), shown("select.all")); + // A row's label also holds its shortcut. + let row = |name: &str| { + let name = name.to_string(); + move |n: &egui_kittest::kittest::AccessKitNode<'_>| n.role() == Role::Button && n.label().is_some_and(|l| l.contains(&name)) + }; + let ungroup_row = h.get_by(row(&ungroup)); + assert!(ungroup_row.accesskit_node().is_disabled()); + assert_eq!(ungroup_row.accesskit_node().description().as_deref(), Some(why.as_str())); + let all_row = h.get_by(row(&all)); + assert!(!all_row.accesskit_node().is_disabled() && all_row.accesskit_node().description().is_none()); + h.get_by(row(&ungroup)).hover(); + h.run_steps(3); + assert!(h.query_by_label(&why).is_some(), "the tooltip says why"); + } + + /// The palette drops its answers when it closes, so opening it again, with the keyboard too, + /// asks its results again. + #[test] + fn the_palette_asks_again_when_it_opens_again() { + let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); + session.execute("select.none", &json!({})).unwrap(); + let mut open = open_on("ungroup", session); + let id = egui::Id::unique("palette-availability"); + let kept = |open: &Open| open.ctx.data(|d| d.get_temp::(id)); + assert!(kept(&open).is_some_and(|a| a.known.contains_key("object.ungroup"))); + open.app.ui.palette_open = false; + open.frame(vec![]); + assert!(kept(&open).is_none(), "the answers go when the palette closes"); + open.app.ui.palette_open = true; + open.frame(vec![]); + assert!(kept(&open).is_some_and(|a| a.asked > 0 && a.known.contains_key("object.ungroup")), "asked again"); + } + + /// What the results' availability depends on changes the key it is kept under: an open dialog, + /// the screen mode, a background job, and a save that marks the document saved without a new + /// revision. + #[test] + fn availability_is_asked_again_when_what_it_depends_on_changes() { + let write_shared: crate::background::SharedWriteFn = std::sync::Arc::new(|_: &str, _: &[u8]| Ok(())); + let services = crate::Services { write_shared: Some(write_shared), ..Default::default() }; + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), services); + let mut key = availability_key(&app); + let mut changed = |app: &VectorcraftApp, what: &str| { + let now = availability_key(app); + assert_ne!(now, key, "{what}"); + key = now; + }; + app.ui.dialog = Some(crate::state::Dialog::new("about", json!({}))); + changed(&app, "a dialog opens"); + app.ui.dialog = None; + changed(&app, "the dialog closes"); + app.ui.screen_mode = 3; + changed(&app, "Presentation Mode"); + let started = crate::background::run(&mut app, true, "Saving".into(), None, |_| Ok(json!({})), |_, r| r).unwrap(); + assert_eq!(started.get("background"), Some(&json!(true)), "{started}"); + changed(&app, "a background job starts"); + app.run("select.all", json!({})).unwrap(); + app.run("object.group", json!({})).unwrap(); + changed(&app, "an edit"); + let revision = app.session.active().map(|d| d.revision); + app.session.active_mut().unwrap().mark_saved(); + assert_eq!(app.session.active().map(|d| d.revision), revision); + changed(&app, "the document is saved"); + } + /// The drawn results are asked whether they can run once per state: keys pressed in the palette - /// keep the answers, and a command run or a click asks again. + /// keep the answers, a command run asks again, and a frame with a click asks again once, + /// without changing the state the answers are kept for. #[test] fn availability_is_read_once_per_state() { let mut session = vectorcraft_testkit::fixtures::Fixture::Multi.session(); @@ -2847,8 +3006,18 @@ mod tests { pressed: false, modifiers: egui::Modifiers::NONE, }; - open.frame(vec![release]); - assert_ne!(read(&open).key, after.key, "a click asks again"); + // The same retries as for the key presses. + let once = (0..20).any(|_| { + open.frame(vec![]); + let before = read(&open); + open.frame(vec![release.clone()]); + let clicked = read(&open); + open.frame(vec![]); + let next = read(&open); + let asked_again = clicked.key == before.key && clicked.asked > before.asked; + asked_again && (next.key, next.asked) == (clicked.key, clicked.asked) + }); + assert!(once, "a click asks again on its own frame only"); } /// Paste is dimmed while the clipboard is empty and nothing can be pasted from the system @@ -2860,7 +3029,7 @@ mod tests { let nodes = open.frame(vec![]); let paste = row_named(&nodes, "Edit › Paste"); assert!(paste.is_disabled(), "{paste:?}"); - assert_eq!(paste.description(), Some(crate::i18n::msg("clipboard is empty").as_str())); + assert_eq!(paste.description(), Some("command `Edit › Paste` is not available right now: clipboard is empty")); open.app.system_paste = true; let nodes = open.frame(vec![]); assert!(!row_named(&nodes, "Edit › Paste").is_disabled()); @@ -2872,27 +3041,45 @@ mod tests { let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); let tools: Vec = build(Lang::EN).into_iter().map(|e| e.id).filter(|id| id.starts_with("tool:")).collect(); assert!(!tools.is_empty()); - assert!(tools.iter().all(|id| unavailable(&app, id).is_none()), "{tools:?}"); + assert!(tools.iter().all(|id| unavailable(&app, id, id).is_none()), "{tools:?}"); let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); - assert_eq!(unavailable(&app, "panel:layers"), None); + assert_eq!(unavailable(&app, "panel:layers", "Window › Layers"), None); app.ui.screen_mode = 3; - assert_eq!(unavailable(&app, "panel:layers").as_deref(), Some("panels can't be shown in Presentation Mode")); + assert_eq!(unavailable(&app, "panel:layers", "Window › Layers").as_deref(), Some("panels can't be shown in Presentation Mode")); } /// A UI command without an engine reason says it is not available, and a filter plug-in or an - /// effect asks about the command its pick runs. + /// effect asks about the command its pick runs. The message names the result as the palette + /// shows it, never by the command's id. #[test] fn a_result_without_an_engine_reason_says_it_is_not_available() { let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); assert!(vectorcraft_engine::find_command("ui.newBrush").is_none()); - assert_eq!(unavailable(&app, "ui.newBrush").as_deref(), Some("command `ui.newBrush` is not available right now")); - assert_eq!(unavailable(&app, "plugin:any.filter").as_deref(), Some("command `plugin.dialog` is not available right now")); + let brush = unavailable(&app, "ui.newBrush", "New Brush…"); + assert_eq!(brush.as_deref(), Some("command `New Brush…` is not available right now")); + let filter = unavailable(&app, "plugin:any.filter", "Object › Plug-ins › Any Filter…"); + assert_eq!(filter.as_deref(), Some("command `Object › Plug-ins › Any Filter…` is not available right now")); let effect = crate::shortcut_editor::effect_items().first().map(|e| format!("effect:{}", e.effect)).expect("an Effect menu item"); - assert!(unavailable(&app, &effect).is_some(), "{effect}"); + let why = unavailable(&app, &effect, "Effect › Any").unwrap_or_else(|| panic!("{effect}")); + assert!(why.starts_with("command `Effect › Any` is not available right now"), "{why}"); let app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); - assert_eq!(unavailable(&app, "ui.newBrush"), None); - assert_eq!(unavailable(&app, "plugin:any.filter"), None); - assert_eq!(unavailable(&app, &effect), None, "{effect}"); + assert_eq!(unavailable(&app, "ui.newBrush", "New Brush…"), None); + assert_eq!(unavailable(&app, "plugin:any.filter", "Any Filter…"), None); + assert_eq!(unavailable(&app, &effect, "Effect › Any"), None, "{effect}"); + } + + /// Every result's reason names it as the palette shows it: no command id appears in it. + #[test] + fn no_reason_shows_a_command_id() { + let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let entries = build(Lang::EN); + let reasons: Vec<(String, String)> = + entries.iter().filter_map(|e| unavailable(&app, &e.id, &e.shown).map(|why| (e.id.clone(), why))).collect(); + assert!(reasons.len() > 100, "with no document most results can't run: {}", reasons.len()); + for (id, why) in &reasons { + let command = crate::keymap::command_of(id).id; + assert!(!why.contains(&format!("`{command}`")), "{id}: {why}"); + } } /// Screen readers stay on the field: its description names the highlighted result and its diff --git a/crates/ui-egui/src/shortcut_editor.rs b/crates/ui-egui/src/shortcut_editor.rs index cbf90d9ecd..0697b4bde7 100644 --- a/crates/ui-egui/src/shortcut_editor.rs +++ b/crates/ui-egui/src/shortcut_editor.rs @@ -918,17 +918,27 @@ pub(crate) fn menu_target(id: &str) -> Option<(String, Value)> { /// status line ([`dimmed`]), as for Remove Background… with no image selected. pub(crate) fn menu_target_now(app: &VectorcraftApp, id: &str) -> Option> { let target = menu_target(id)?; - Some(if menus::enabled(app, id) { Ok(target) } else { dimmed(app, id) }) + Some(match dimmed(app, id, id) { + None => Ok(target), + Some(why) => Err(why), + }) } -/// What [`menu_target_now`] gives for command `id` while its menu bar item is dimmed: the status -/// line, with the engine's reason when it gives one. The app's own rules ([`menus::enabled`]) dim -/// UI commands, and some commands the engine would run, without giving a reason. -pub(crate) fn dimmed(app: &VectorcraftApp, id: &str) -> Result<(String, Value), String> { - let Some(why) = vectorcraft_engine::find_command(id).and_then(|c| (c.enabled)(&app.session).err()) else { - return Err(format!("command `{id}` is not available right now")); +/// What [`menu_target_now`] gives for command `id` while its menu bar item is dimmed, or `None` +/// while the item is not dimmed: the status line, which calls the command `name` (its id on the +/// status line), with the engine's reason when it gives one. The app's own rules +/// ([`menus::enabled`]) dim UI commands, and some commands the engine would run, without giving a +/// reason. The engine's check runs at most once. +pub(crate) fn dimmed(app: &VectorcraftApp, id: &str, name: &str) -> Option { + let why = match menus::why_off(app, id)? { + Some(why) => Some(why), + // Dimmed before the engine was asked (no Appearance subject, an input method composing). + None => vectorcraft_engine::find_command(id).and_then(|c| (c.enabled)(&app.session).err()), }; - Err(vectorcraft_engine::EngineError::Disabled(id.to_string(), why).to_string()) + Some(match why { + Some(why) => vectorcraft_engine::EngineError::Disabled(name.to_string(), why).to_string(), + None => format!("command `{name}` is not available right now"), + }) } /// Is `key` a command with no default shortcut that a key press can't run: no item of the menu @@ -2968,13 +2978,19 @@ mod tests { use vectorcraft_testkit::fixtures::Fixture; let none = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); assert!(!menus::enabled(&none, "edit.findReplace")); - assert_eq!(dimmed(&none, "edit.findReplace"), Err("command `edit.findReplace` is not available right now: no document open".into())); + let why = "command `edit.findReplace` is not available right now: no document open"; + assert_eq!(dimmed(&none, "edit.findReplace", "edit.findReplace").as_deref(), Some(why)); + // A name to show takes the id's place. + let shown = "command `Edit › Find and Replace…` is not available right now: no document open"; + assert_eq!(dimmed(&none, "edit.findReplace", "Edit › Find and Replace…").as_deref(), Some(shown)); let empty = VectorcraftApp::new(Fixture::Empty.session(), crate::Services::default()); for id in ["appearance.addFill", "ui.cropImage"] { assert!(!menus::enabled(&empty, id), "{id}"); assert!(vectorcraft_engine::find_command(id).is_none_or(|c| (c.enabled)(&empty.session).is_ok()), "{id}: the engine gives no reason"); - assert_eq!(dimmed(&empty, id), Err(format!("command `{id}` is not available right now"))); + assert_eq!(dimmed(&empty, id, id), Some(format!("command `{id}` is not available right now"))); } + assert!(menus::enabled(&empty, "edit.findReplace")); + assert_eq!(dimmed(&empty, "edit.findReplace", "edit.findReplace"), None, "not dimmed"); } /// Every command the editor lists, run as a key press runs it on a document with one or with diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 4a1d5c828e..505137a39b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1312,7 +1312,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur The Command Palette ranks the commands listed in Recent Commands first among the results that match a query as well as they do, the most recent first, and below every result that matches it better: after a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, so Enter runs it again. A recent pick ranks after the whole-query match, the word grades and the matches through a typo, a description or a word with the same meaning, and before the kind of result and the name's length. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. This is VectorCraft's own behavior (`palette::search` test `a_recent_pick_ranks_first_within_its_grades`; `palette` tests `a_recent_pick_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_recent_picks`). The Command Palette also counts how many times each command is picked and ranks the commands picked most often first among the results that match a query as well as they do, also after they leave Recent Commands, and below every result that matches it better. Counts are compared in grades that double: grade 1 starts at 1 pick, grade 2 at 3, grade 3 at 7, and so on up to grade 9, and a command picked once ranks above the commands never picked. The grade ranks after the word grades and the typo, description and same-meaning matches, and before the place among the recent picks. The count is kept for at most 200 commands: a new command then removes the one with the fewest picks, of those the one picked longest ago. When a count reaches 1,000, every count is halved and commands left at 0 are dropped. The counts are saved with the other interface settings (`command_uses` in `ui.json`); a count above 999 loads as 999 and an unreadable entry is dropped. The web build keeps them for the session. This is VectorCraft's own behavior (`palette::search` test `a_command_picked_often_ranks_first_within_its_grades`; `palette` tests `a_command_picked_often_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_pick_counts`, `a_count_does_not_pass_a_better_match`, `pick_counts_rank_in_grades_that_double`, `the_201st_command_removes_the_least_used_and_keeps_itself`, `counts_are_halved_at_one_thousand`, `saved_pick_counts_load_what_is_readable`). A Command Palette query word also finds a command by what the command's description says: "transparent background" lists Remove Background… among the first 3 results, and "png" lists it after every result with "png" in its name or menu path. The description is the command's params text (an engine or plug-in command's, a UI command's, or an effect's) without each `{…}` group that is not inside a `{`, `[` or `(` group, without each such `[…]` or `(…)` group just after a `→`, and without the `→` before a removed group, cut to its first 300 characters at the end of a word. The words of a schema ("corners" for Remove Background…) and of a result written as a group do not find the command; a result written as words after a `→` stays in the description. Words of 2 characters or fewer, words with no letter, and "the", "and", "ids", "true", "false" and "null" are left out. A query word that is a word of a description, shares an English base word with one, starts one or has the same meaning as one finds the result, and such a result ranks below every result that the query matches in its name, menu path or id, as text inside a word or through a typo. Descriptions are English only, and a typo does not match them. Tools, panels and filter plug-ins have no description (`palette::search` tests `a_description_leaves_out_the_schema_and_the_result`, `a_word_of_the_description_finds_the_result`, `a_description_match_ranks_below_a_typo`, `words_of_a_description_find_the_command`). - A Command Palette result that cannot run now stays in its place in the list and is drawn dimmed: an engine command whose engine check fails (Ungroup with nothing selected, Paste with an empty clipboard and nothing to paste from the system clipboard), a UI command the menus dim, a filter plug-in or an effect whose menu item is dimmed, and a panel in Presentation Mode. Tools are never dimmed. The engine's reason, or that the command is not available right now, shows on hover, in the row's screen-reader description and in the footer while the row is highlighted, beside the count or, under the recent picks of an empty search, on a line of its own. Only the drawn rows are checked, each once for as long as the state it was checked in lasts: a command run, an edit, a change of selection, document, history, clipboard, language, screen mode or open dialog, a save that marks the document saved, a background save, export, file read, plug-in run or trace that starts, ends or shows its progress window, or a click checks them again on the next frame, while typing in the search field does not. The check never changes the ranking. A pick of a dimmed result does what it did before (`palette` tests `a_result_that_cannot_run_now_is_dimmed_and_says_why`, `paste_is_dimmed_only_while_nothing_can_be_pasted`, `tools_are_never_dimmed_and_panels_are_in_presentation_mode`, `a_result_without_an_engine_reason_says_it_is_not_available`, `a_recent_pick_that_cannot_run_now_says_why`, `availability_is_read_once_per_state`). + A Command Palette result that cannot run now stays in its place in the list and is drawn dimmed: an engine command whose engine check fails (Ungroup with nothing selected, Paste with an empty clipboard and nothing to paste from the system clipboard), a UI command the menus dim, a filter plug-in or an effect whose menu item is dimmed, and a panel in Presentation Mode. Tools are never dimmed. The reason shows on hover, in the row's screen-reader description, on a second line of the search field's screen-reader description and in the footer while the row is highlighted, beside the count or, under the recent picks of an empty search, on a line of its own. The reason is the status line a pick of the dimmed menu item gives, with the result's name in place of the command's id: "command `Object › Ungroup` is not available right now: nothing selected", or without the engine's reason when it gives none. The Recent Commands list beside the search field draws such a pick dimmed too, with the same reason on hover and for screen readers. Only the drawn rows are checked, each once for as long as the state it was checked in lasts: a command run, an edit, a change of selection, document, history, clipboard, language, screen mode or open dialog, a save that marks the document saved, or a background save, export, file read, plug-in run or trace that starts, ends or shows its progress window checks them again on the next frame, and a frame with a click checks them again on that frame only. Typing in the search field does not check them again, and the palette checks them again each time it opens. The check never changes the ranking. A pick of a dimmed result does what it did before (`palette` tests `a_result_that_cannot_run_now_is_dimmed_and_says_why`, `hovering_a_result_that_cannot_run_now_says_why`, `paste_is_dimmed_only_while_nothing_can_be_pasted`, `tools_are_never_dimmed_and_panels_are_in_presentation_mode`, `a_result_without_an_engine_reason_says_it_is_not_available`, `no_reason_shows_a_command_id`, `a_recent_pick_that_cannot_run_now_says_why`, `a_recent_command_that_cannot_run_now_is_dimmed_in_the_list`, `availability_is_asked_again_when_what_it_depends_on_changes`, `availability_is_read_once_per_state`, `the_palette_asks_again_when_it_opens_again`). `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. From e4d2922b210a3e3d4f9448fd0261fa0e35da4d96 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 20:28:17 -0800 Subject: [PATCH 4/6] Command Palette: a palette closed and opened at once starts on its first row A pick or a press outside the palette now drops the highlight and the availability answers on the frame that closes it, so a command that opens the palette again before a closed frame is drawn starts on the first row and checks the rows again. The ranking line now says a recent pick ranks after the pick count's grade. --- crates/ui-egui/src/palette.rs | 33 +++++++++++++++++++++++++++++++-- docs/target-app-parity.md | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index df5ec12d9e..1be4f36489 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -1086,10 +1086,18 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { ctx.request_repaint(); } let sel_key = matches.get(sel).map(|e| e.id.clone()).unwrap_or_default(); + // A palette that closes on this frame forgets its highlight and its answers here, as a closed + // frame does, so a command that opens it again before that frame starts it afresh. + let closing = run.is_some() || outside; ctx.data_mut(|d| { - d.insert_temp::(sel_id, (sel, q, offset, view, sel_key)); + if closing { + d.remove::(sel_id); + d.remove::(availability_id); + } else { + d.insert_temp::(sel_id, (sel, q, offset, view, sel_key)); + d.insert_temp(availability_id, availability); + } d.insert_temp(rsel_id, rsel); - d.insert_temp(availability_id, availability); }); if let Some(id) = run { app.ui.palette_open = false; @@ -1939,6 +1947,27 @@ mod tests { assert!(top.2 >= f64::from(open.popup().top()), "the first row is in view: {shown:?}"); } + /// A palette closed by a press outside it and opened again before a closed frame is drawn + /// starts with its first row highlighted and asks its results again whether they can run. + #[test] + fn the_palette_opened_again_at_once_after_closing_starts_afresh() { + let mut open = Open::new("", WINDOW); + open.app.ui.recent_commands = vec!["paint.swap".into(), "object.group".into(), "view.zoomIn".into()]; + open.frame(vec![]); + open.press(egui::Key::ArrowDown, 2); + assert_eq!(open.highlighted(), 2); + let at = egui::pos2(2.0, 2.0); + assert!(!open.popup().contains(at), "{at:?} is outside {:?}", open.popup()); + let press = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE }; + open.frame(vec![egui::Event::PointerMoved(at), press]); + assert!(!open.app.ui.palette_open, "the press outside closes the palette"); + let availability = egui::Id::unique("palette-availability"); + assert!(open.ctx.data(|d| d.get_temp::(availability)).is_none(), "the answers go when the palette closes"); + open.app.ui.palette_open = true; + open.frame(vec![]); + assert_eq!(open.highlighted(), 0, "the first row is highlighted"); + } + /// #1757: Up and Down move the highlighted result, wrapping at the ends; a new query starts /// from the first again. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 1ae54a2154..a75f48513a 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1405,7 +1405,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur A Command Palette query word in an English plural or verb form finds a result whose English name or menu path holds the base word: "rounded corners" lists Effect › Stylize › Round Corners… first, and "scaling" finds Object › Transform › Scale…. The search drops `'s`; `es` after `s`, `x`, `z`, `ch` or `sh` (also trying the word with only its `s` dropped, so "rasterizes" finds Rasterize…); a final `s` in words of more than 3 letters, except after `ss`, `us` or `is`; `ing` in words of more than 5 letters and `ed` in words of more than 4. After `ing` or `ed`, a doubled `b`, `d`, `g`, `m`, `n`, `p`, `r` or `t` is tried both single and doubled, the single letter only when at least 3 letters are left ("cutting" meets Cut, "added" meets Add); otherwise the word is also tried with an `e` ("scaling" meets Scale…). It turns `ies` into `y` or `ie` in words of more than 5 letters and `sses` into `ss`, and leaves `series` and `species` as they are. Among results that the whole query matches the same way (as an id, as a label, at the start of a label, as initials, or none of these), a result whose name holds the base word of a query word ranks below one that holds the query word whole and above one where the query word only starts a word of the name, so "scale zz" lists a name with "Zz Scaling" above one with "Zz Scalers". "scale" alone still lists "Scalers" above "Scaling", because "Scalers" starts with the query. A partly typed word that is not itself a word of any result ("scal") does not meet a base word. Names shown in other languages and ids are not changed this way, and every result found before is still found (`palette::search` tests `plurals_and_verb_forms_meet_their_base_word`, `a_plural_or_verb_form_finds_the_result`, `a_better_word_grade_ranks_first`, `a_partly_typed_word_does_not_lift_a_verb_form`, `a_whole_query_tier_comes_before_a_stem_form`, `results_matched_without_a_stem_keep_their_order`). A Command Palette query word with a typo still finds the result: "gruop" lists Object › Group first, and "eyedroper", "rectange" and "elipse" list the same first results as the words spelled right, the Eyedropper, Rectangle and Ellipse tools among them. When a query word of 4 or more letters is not a word, a base word or the start of a word of any result's name, menu path or id, the search compares it with the words of result names and menu paths, and a word 1 edit away (2 for a query word of 8 or more letters) matches; a letter added, left out or changed, or two letters next to each other swapped, is one edit. A query word meets at most the 32 nearest such words. Results matched through a typo come after every result the query matches without one, and among them the query is read with the misspelled word replaced by the word it meets, so they come in the order the word spelled right gives; then a result whose label holds the word comes before one whose menu path holds it. Ids, and query words and result words with Chinese, Japanese or Korean letters, are not compared this way, and results without typos keep their order (`palette::search` tests `edits_are_counted_up_to_a_bound`, `a_word_with_a_typo_finds_the_result`, `a_typo_meets_at_most_32_words`, `misspelled_words_find_the_command`). A Command Palette query word also finds a result whose name or menu path holds a word with the same meaning: "remove bg" lists Remove Background… first, "outline text" lists Type › Create Outlines first, and "flip", "combine", "vectorize" and "colour" list Reflect…, Unite, an Image Trace command and the Color panel among the first 3 results. The words come from VectorCraft's own table of 21 groups of English words (`palette/words.rs`, at most 60 groups of at most 6 words); a word that is the whole label of another command, such as Merge or Mirror, is in no group, and neither is Insert. A word or its English base word that is in a group meets the other words of its group in labels and menu paths, and their base words, but not ids or word starts. A result whose label holds the word itself ranks above one whose label holds a word with the same meaning, which ranks above one whose menu path holds the word, so "type" now lists Scale Text Attributes above Type › Orientation › Vertical. A catalog may add a group's words in its language with a row in the `search` context (the group's English words joined by ", ", then that language's words), used while that language is the UI language; no catalog has to have these rows (`palette::search` tests `a_word_with_the_same_meaning_finds_the_result`, `a_catalog_row_adds_words_to_a_group`, `words_with_the_same_meaning_find_the_command`; `palette::words` tests; `i18n` test `search_rows_name_a_group_and_add_single_words`). - The Command Palette ranks the commands listed in Recent Commands first among the results that match a query as well as they do, the most recent first, and below every result that matches it better: after a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, so Enter runs it again. A recent pick ranks after the whole-query match, the word grades and the matches through a typo, a description or a word with the same meaning, and before the kind of result and the name's length. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. This is VectorCraft's own behavior (`palette::search` test `a_recent_pick_ranks_first_within_its_grades`; `palette` tests `a_recent_pick_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_recent_picks`). + The Command Palette ranks the commands listed in Recent Commands first among the results that match a query as well as they do and were picked as often (see the pick counts below), the most recent first, and below every result that matches it better: after a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, so Enter runs it again. A recent pick ranks after the whole-query match, the word grades, the matches through a typo, a description or a word with the same meaning, and the pick count's grade, and before the kind of result and the name's length. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. This is VectorCraft's own behavior (`palette::search` test `a_recent_pick_ranks_first_within_its_grades`; `palette` tests `a_recent_pick_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_recent_picks`). The Command Palette also counts how many times each command is picked and ranks the commands picked most often first among the results that match a query as well as they do, also after they leave Recent Commands, and below every result that matches it better. Counts are compared in grades that double: grade 1 starts at 1 pick, grade 2 at 3, grade 3 at 7, and so on up to grade 9, and a command picked once ranks above the commands never picked. The grade ranks after the word grades and the typo, description and same-meaning matches, and before the place among the recent picks. The count is kept for at most 200 commands: a new command then removes the one with the fewest picks, of those the one picked longest ago. When a count reaches 1,000, every count is halved and commands left at 0 are dropped. The counts are saved with the other interface settings (`command_uses` in `ui.json`); a count above 999 loads as 999 and an unreadable entry is dropped. The web build keeps them for the session. This is VectorCraft's own behavior (`palette::search` test `a_command_picked_often_ranks_first_within_its_grades`; `palette` tests `a_command_picked_often_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_pick_counts`, `a_count_does_not_pass_a_better_match`, `pick_counts_rank_in_grades_that_double`, `the_201st_command_removes_the_least_used_and_keeps_itself`, `counts_are_halved_at_one_thousand`, `saved_pick_counts_load_what_is_readable`). A Command Palette query word also finds a command by what the command's description says: "transparent background" lists Remove Background… among the first 3 results, and "png" lists it after every result with "png" in its name or menu path. The description is the command's params text (an engine or plug-in command's, a UI command's, or an effect's) without each `{…}` group that is not inside a `{`, `[` or `(` group, without each such `[…]` or `(…)` group just after a `→`, and without the `→` before a removed group, cut to its first 300 characters at the end of a word. The words of a schema ("corners" for Remove Background…) and of a result written as a group do not find the command; a result written as words after a `→` stays in the description. Words of 2 characters or fewer, words with no letter, and "the", "and", "ids", "true", "false" and "null" are left out. A query word that is a word of a description, shares an English base word with one, starts one or has the same meaning as one finds the result, and such a result ranks below every result that the query matches in its name, menu path or id, as text inside a word or through a typo. Descriptions are English only, and a typo does not match them. Tools, panels and filter plug-ins have no description (`palette::search` tests `a_description_leaves_out_the_schema_and_the_result`, `a_word_of_the_description_finds_the_result`, `a_description_match_ranks_below_a_typo`, `words_of_a_description_find_the_command`). A Command Palette result that cannot run now stays in its place in the list and is drawn dimmed: an engine command whose engine check fails (Ungroup with nothing selected, Paste with an empty clipboard and nothing to paste from the system clipboard), a UI command the menus dim, a filter plug-in or an effect whose menu item is dimmed, and a panel in Presentation Mode. Tools are never dimmed. The reason shows on hover, in the row's screen-reader description, on a second line of the search field's screen-reader description and in the footer while the row is highlighted, beside the count or, under the recent picks of an empty search, on a line of its own. The reason is the status line a pick of the dimmed menu item gives, with the result's name in place of the command's id: "command `Object › Ungroup` is not available right now: nothing selected", or without the engine's reason when it gives none. The Recent Commands list beside the search field draws such a pick dimmed too, with the same reason on hover and for screen readers. Only the drawn rows are checked, each once for as long as the state it was checked in lasts: a command run, an edit, a change of selection, document, history, clipboard, language, screen mode or open dialog, a save that marks the document saved, or a background save, export, file read, plug-in run or trace that starts, ends or shows its progress window checks them again on the next frame, and a frame with a click checks them again on that frame only. Typing in the search field does not check them again, and the palette checks them again each time it opens. The check never changes the ranking. A pick of a dimmed result does what it did before (`palette` tests `a_result_that_cannot_run_now_is_dimmed_and_says_why`, `hovering_a_result_that_cannot_run_now_says_why`, `paste_is_dimmed_only_while_nothing_can_be_pasted`, `tools_are_never_dimmed_and_panels_are_in_presentation_mode`, `a_result_without_an_engine_reason_says_it_is_not_available`, `no_reason_shows_a_command_id`, `a_recent_pick_that_cannot_run_now_says_why`, `a_recent_command_that_cannot_run_now_is_dimmed_in_the_list`, `availability_is_asked_again_when_what_it_depends_on_changes`, `availability_is_read_once_per_state`, `the_palette_asks_again_when_it_opens_again`). From da0e39289a61d63cd5ec6a5673b8c5fc881a06c8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 06:25:29 -0800 Subject: [PATCH 5/6] Command Palette: a pick of a dimmed result runs nothing With no document open, the Asset Export commands are listed dimmed, but a pick of one still opened the Asset Export panel. A pick of any result that is drawn dimmed now leaves everything as it is, and the status line says why the command can't run, as the row does. --- crates/ui-egui/src/palette.rs | 37 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index cd740dbcb9..8130493277 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -418,9 +418,9 @@ fn build_in(lang: crate::i18n::Lang, native: bool) -> Vec { /// Runs the palette result `id`: selects a tool, or invokes a command with the params its entry /// stands for. A command whose menu bar item gives params runs what a click on that item runs /// ([`crate::shortcut_editor::menu_target_now`]), so Clean Up… and Find and Replace… open their -/// dialogs. While that item is dimmed, no dialog opens and the status line says why the command -/// can't run. A panel's result shows the panel, and an effect's result runs what its Effect menu -/// item runs ([`crate::keymap::command_of`]). +/// dialogs. While a result is dimmed ([`unavailable`]), its pick runs nothing, opens no dialog or +/// panel, and the status line says why the command can't run. A panel's result shows the panel, +/// and an effect's result runs what its Effect menu item runs ([`crate::keymap::command_of`]). pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { if let Some(tool) = id.strip_prefix("tool:") { app.select_tool(tool); @@ -435,11 +435,9 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { } } else if id.starts_with("plugin:") || id.starts_with("effect:") { let command = crate::keymap::command_of(id); - // While the Effect menu dims the item (nothing selected), no dialog opens and the status - // line says why. - if id.starts_with("effect:") - && let Some(why) = crate::shortcut_editor::dimmed(app, &command.id, &command.id) - { + // While the item is dimmed (an effect with nothing selected), no dialog opens and the + // status line says why. + if let Some(why) = crate::shortcut_editor::dimmed(app, &command.id, &command.id) { app.status(why); } else { menus::invoke(app, &command.id, command.params); @@ -448,7 +446,12 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { match crate::shortcut_editor::menu_target_now(app, id) { Some(Ok((id, p))) => menus::invoke(app, &id, p), Some(Err(why)) => app.status(why), - None => menus::invoke(app, id, json!({})), + // A dimmed result does not run: the Asset Export commands with no document open show + // no panel. + None => match crate::shortcut_editor::dimmed(app, id, id) { + Some(why) => app.status(why), + None => menus::invoke(app, id, json!({})), + }, } } } @@ -1420,6 +1423,22 @@ mod tests { } } + /// With no document open, the Asset Export commands are dimmed, and a pick of one shows no panel + /// and says why it can't run, as the row's description does. + #[test] + fn a_dimmed_asset_export_command_does_not_open_its_panel() { + let ids = ["assets.export", "assets.remove", "assets.rename", "assets.settings.set", "assets.export3D", "assets.set3DFormat"]; + for id in ids { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let why = unavailable(&app, id, id); + assert!(why.is_some(), "{id} is dimmed with no document open"); + app.ui.status.clear(); + run_pick(&mut app, id); + assert!(!crate::panel_docking::showing(&app.ui, crate::panels::asset_export::ID), "{id}: {}", app.ui.status); + assert_eq!(Some(app.ui.status.clone()), why, "{id}"); + } + } + /// The open dialog's kind and fields, the active document's undo depth and the status line. type Outcome = (Option<(String, serde_json::Map)>, Option, String); From 591480d33ba2f575fc583378b7732cc5fb23c04d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 14:08:12 -0800 Subject: [PATCH 6/6] Command Palette: Enter runs the query typed in its frame, and Paste is dimmed with no document - Text typed into the search field in the frame that presses Enter changed the query after the results were listed, so Enter ran the old list's highlighted result (on an empty search, the last pick). Enter now runs the first result of the query as typed. - `menus::why_off` treated Paste as enabled while the system clipboard read as pasteable, also with no document open, until the next clipboard check. The override now needs an open document, and the engine's reason shows. - `a_result_that_cannot_run_now_is_dimmed_and_says_why` looks up the row's color by the name the row draws (without its menu path). `paste_is_dimmed_only_while_nothing_can_be_pasted` finds the Paste row by its full screen-reader label. `screen_readers_hear_the_kind_and_home` checks the first line of the field's description, since Round Corners can't run with no document and its reason goes on a second line. --- crates/ui-egui/src/menus/state.rs | 5 ++- crates/ui-egui/src/palette.rs | 68 ++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 52dda32983..de8920443b 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -226,8 +226,9 @@ pub(crate) fn why_off(app: &VectorcraftApp, id: &str) -> Option> if let Some(c) = vectorcraft_engine::find_command(id) { return match (c.enabled)(&app.session) { Ok(()) => None, - // The system clipboard's contents can be pasted with an empty internal clipboard. - Err(_) if app.system_paste && id.starts_with("edit.paste") => None, + // The system clipboard's contents can be pasted into an open document with an empty + // internal clipboard. + Err(_) if app.system_paste && app.session.active().is_some() && id.starts_with("edit.paste") => None, Err(why) => Some(Some(why)), }; } diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 4645a86c02..41e999db98 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -1566,12 +1566,20 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } }); }); - if !list_open - && !history_focused - && ui.input(|i| i.key_pressed(egui::Key::Enter)) - && let Some(e) = matches.get(sel) - { - run = Some(e.id.clone()); + if !list_open && !history_focused && ui.input(|i| i.key_pressed(egui::Key::Enter)) { + // Text typed in the frame that pressed Enter changed the query after the results + // were listed: Enter runs the first result of the new query. + let typed = app.ui.palette_query.to_lowercase(); + let picked = if typed == q { + matches.get(sel).copied() + } else if typed.trim().is_empty() { + recent.first().copied() + } else { + matching(&entries, &typed, &app.ui.recent_commands, &app.ui.command_uses).first().copied() + }; + if let Some(e) = picked { + run = Some(e.id.clone()); + } } }); }); @@ -2458,6 +2466,25 @@ mod tests { assert_eq!(open.app.ui.recent_commands, ["paint.swap", "object.group"]); } + /// Text typed into an empty search in the frame that presses Enter runs the first result of the + /// new query, not the last pick the empty search listed. + #[test] + fn enter_with_text_typed_in_its_frame_runs_the_new_querys_first_result() { + let mut open = Open::new("", WINDOW); + open.app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + open.app.ui.recent_commands = vec!["paint.swap".into()]; + open.app.ui.palette_open = true; + open.frame(vec![]); + open.frame(vec![]); + let entries = entries(&open.ctx, Lang::EN); + let first = super::matching(&entries, "select all", &open.app.ui.recent_commands, &open.app.ui.command_uses)[0].id.clone(); + assert_ne!(first, "paint.swap"); + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + open.frame(vec![egui::Event::Text("select all".into()), enter]); + assert!(!open.app.ui.palette_open, "the palette closes"); + assert_eq!(open.app.ui.recent_commands.first(), Some(&first), "{}", open.app.ui.status); + } + /// The palette opens again with its first row highlighted, even when it shows the same rows. #[test] fn the_palette_opens_again_with_its_first_row_highlighted() { @@ -3558,7 +3585,8 @@ mod tests { assert_eq!(said, "Effect, Round Corners…, Effect › Stylize"); let row = rows(&nodes).into_iter().find(|r| r.0 == said).expect("its row is drawn"); assert!((row.3 - row.2 - f64::from(ROW_HEIGHT)).abs() < 0.01, "{row:?}"); - assert!(field_description(&nodes).ends_with(&said), "{}", field_description(&nodes)); + // With no document, Round Corners can't run now, and the reason goes on a second line. + assert!(field_place(&nodes).ends_with(&said), "{}", field_description(&nodes)); let open = Open::new("group selection", WINDOW); assert_eq!(open.said("tool:groupSelection"), "Tool, Group Selection Tool, Toolbar, in the Direct Selection Tool group"); let mut open = Open::new("layers", WINDOW); @@ -3657,7 +3685,8 @@ mod tests { assert!(ungroup.is_disabled(), "{ungroup:?}"); assert_eq!(ungroup.description(), Some(why.as_str())); let t = Tokens::get(&open.ctx); - assert_eq!(open.color_of(&entry.shown), Some(t.text_disabled), "the name is drawn dimmed"); + // The row draws the name without the menu path its home shows. + assert_eq!(open.color_of(label_of(entry)), Some(t.text_disabled), "the name is drawn dimmed"); let footer_says = |nodes: &[egui::accesskit::Node]| labels(nodes).contains(&why); assert!(footer_says(&nodes), "{:?}", labels(&nodes)); // The arrow keys leave screen readers on the search field, so its description says why too. @@ -3669,7 +3698,7 @@ mod tests { let nodes = open.frame(vec![]); let ungroup = row_named(&nodes, &name); assert!(!ungroup.is_disabled() && ungroup.description().is_none(), "{ungroup:?}"); - assert_eq!(open.color_of(&entry.shown), Some(t.text)); + assert_eq!(open.color_of(label_of(entry)), Some(t.text)); assert!(!footer_says(&nodes), "{:?}", labels(&nodes)); assert_eq!(field_description(&nodes), place); // Whether a result can run never moves it. @@ -3859,13 +3888,30 @@ mod tests { fn paste_is_dimmed_only_while_nothing_can_be_pasted() { let mut open = open_on("paste", vectorcraft_testkit::fixtures::Fixture::Multi.session()); open.app.system_paste = false; + let name = open.said("edit.paste"); let nodes = open.frame(vec![]); - let paste = row_named(&nodes, "Edit › Paste"); + let paste = row_named(&nodes, &name); assert!(paste.is_disabled(), "{paste:?}"); assert_eq!(paste.description(), Some("command `Edit › Paste` is not available right now: clipboard is empty")); open.app.system_paste = true; let nodes = open.frame(vec![]); - assert!(!row_named(&nodes, "Edit › Paste").is_disabled()); + assert!(!row_named(&nodes, &name).is_disabled()); + } + + /// With no document open, Paste is dimmed with the engine's reason, though the system + /// clipboard still reads as pasteable until its next check. + #[test] + fn paste_is_dimmed_with_no_document_open() { + let mut open = open_on("paste", vectorcraft_engine::Session::new()); + open.app.system_paste = true; + let name = open.said("edit.paste"); + let nodes = open.frame(vec![]); + let paste = row_named(&nodes, &name); + assert!(paste.is_disabled(), "{paste:?}"); + let reason = (vectorcraft_engine::find_command("edit.paste").unwrap().enabled)(&open.app.session).unwrap_err(); + let why = format!("command `Edit › Paste` is not available right now: {reason}"); + assert_eq!(paste.description(), Some(why.as_str())); + assert!(!menus::enabled(&open.app, "edit.paste")); } /// A tool can always be chosen; a panel can't be shown in Presentation Mode, and says so.