From b85d0b25a0e044a61dff2f49b1ba194df741eaf2 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 17:42:12 +0100 Subject: [PATCH] Remove AppCatalog::shown_only A catalog-wide set of ids whose chords the board passes over is a second key dispatcher beside the board, and it ignores the ids a linked set defines. Review asks for it out of this PR; its replacement comes in a PR of its own. Removes the builder and the shown_only field, the board's leaves_key skip path with the runs_now and hold/press filters that read it, docs/contract-api.md's line for it, and its trial in crates/ui-shell/tests/it/commands/app_catalog.rs. --- .../ui-contract/src/runtime/commands/board.rs | 27 ++++------------ .../ui-contract/src/runtime/commands/mod.rs | 26 ++------------- .../ui-shell/tests/it/commands/app_catalog.rs | 32 ------------------- docs/contract-api.md | 1 - 4 files changed, 8 insertions(+), 78 deletions(-) diff --git a/crates/ui-contract/src/runtime/commands/board.rs b/crates/ui-contract/src/runtime/commands/board.rs index 9b5355c891..8d3474f5cd 100644 --- a/crates/ui-contract/src/runtime/commands/board.rs +++ b/crates/ui-contract/src/runtime/commands/board.rs @@ -666,12 +666,6 @@ impl Board { self.instances.get(id).is_some_and(|i| self.live(ctx, i)) } - /// Whether the app dispatches the keys of `command` itself ([`AppCatalog::shown_only`]): the board shows its chord - /// but passes over its bindings when it matches a key. Only a command the linked sets do not define. - fn leaves_key(&self, command: &CommandRef) -> bool { - self.app.as_ref().is_some_and(|app| app.is_shown_only(command)) && self.registry.get(&command.id).is_none() - } - /// The definition of `command`: the linked sets' by id, else the frame's app catalog's. fn def(&self, command: &CommandRef) -> Option<&CommandDef> { self.registry.get(&command.id).or_else(|| self.app.as_ref()?.get(command)) @@ -1303,7 +1297,7 @@ pub(crate) fn runs_now(ctx: &Context, viewport: ViewportId, chord: &Chord) -> bo board.key_scopes(&chain) }); let Some(keys) = keys else { return false }; - let enabled = |command: &CommandRef| !with(ctx, |board| board.leaves_key(command)) && resolve_from(ctx, command, None).0.enabled; + let enabled = |command: &CommandRef| resolve_from(ctx, command, None).0.enabled; keys.matching(false, |active, outer| !matches!(keys.keymap.lookup_where(chord, false, active, outer, &enabled), craft_keymap::Lookup::None)) } @@ -2222,14 +2216,8 @@ pub(crate) fn begin(ctx: &Context) { }; // A binding whose command is disabled where the press lands (a window command with no floating window, a canvas's // view command it does not offer) is passed over: the press runs the next binding of its chord, in an outer scope, - // or of its next chord candidate, as if the disabled one were unbound. So is a binding of a command whose keys the - // app dispatches itself (`AppCatalog::shown_only`), whatever its state. - let leaves_key = |command: &CommandRef| with(ctx, |board| board.leaves_key(command)); - let board_runs = |hit: &Hit| !leaves_key(&hit.command); + // or of its next chord candidate, as if the disabled one were unbound. let enabled = |command: &CommandRef| { - if leaves_key(command) { - return false; - } let (_, instance) = with(ctx, |board| board.target_of(ctx, command, &board.here)); resolve_in(ctx, command, instance, Reach::Focus, None, Reads::default()).0.enabled }; @@ -2267,9 +2255,7 @@ pub(crate) fn begin(ctx: &Context) { // completes no double press and settles no wait, and the key a momentary or tool command holds stays // held by its press. The key of a wait or of a hold binding repeats nothing. let typing = typing_at(shortcut); - if wait.as_ref().is_some_and(|wait| Some(wait.key) == key) - || keys.hold(&shortcuts.layout, &shortcut.input, typing).is_some_and(|hold| board_runs(&hold)) - { + if wait.as_ref().is_some_and(|wait| Some(wait.key) == key) || keys.hold(&shortcuts.layout, &shortcut.input, typing).is_some() { continue; } let tap = keys.press(&shortcuts.layout, &shortcut.input, typing, Some((&mut matcher, time, true, &enabled))); @@ -2282,16 +2268,15 @@ pub(crate) fn begin(ctx: &Context) { let typing = typing_at(shortcut); let hold = key .filter(|_| !typing && !modal_at_start) - .and_then(|key| keys.hold(&shortcuts.layout, &shortcut.input, typing).filter(board_runs).map(|hold| (key, hold))); + .and_then(|key| keys.hold(&shortcuts.layout, &shortcut.input, typing).map(|hold| (key, hold))); let tap = keys.press(&shortcuts.layout, &shortcut.input, typing, Some((&mut matcher, time, false, &enabled))); match (hold, tap) { (Some((key, hold)), tap) => wait = Some(HoldWait { key, hold, since: time, delay, tap, viewport }), (None, Some(tap)) => fired.extend(press(tap, key, time, Some(shortcut.place))), // A chord that binds only disabled commands runs nothing; the app hears of the first one, to say - // why it did not run as a menu row's hint does, and may receive it as declined. A chord the app - // dispatches itself is the app's: it hears nothing of it here. + // why it did not run as a menu row's hint does, and may receive it as declined. (None, None) => { - if let Some(hit) = keys.press(&shortcuts.layout, &shortcut.input, typing, None).filter(board_runs) { + if let Some(hit) = keys.press(&shortcuts.layout, &shortcut.input, typing, None) { let (app, instance) = with(ctx, |board| board.target_of(ctx, &hit.command, &board.here)); let resolved = resolve_once(ctx, &hit.command, instance, Reach::Focus, None); decline(ctx, hit.clone(), app, &resolved, time); diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index d726687d7e..99b330a8de 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -56,7 +56,7 @@ use craft_behavior::edit_history::Step; use craft_keymap::{Chord, Overrides}; use egui::{Context, Id, ViewportId}; use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::sync::Arc; /// Commands an app defines at run time (plug-ins, its tool list), all in the app scope ([`Scope::app`]). They join @@ -71,8 +71,6 @@ pub struct AppCatalog { replaced: Arc<[(String, Vec)]>, /// Which chords fire while a text component has the keyboard (`typing_rule`); `None` keeps the keymap's default. typing: Option, - /// The ids of the catalog's commands whose keys the app dispatches itself (`shown_only`). - shown_only: Arc>, } impl AppCatalog { @@ -86,7 +84,7 @@ impl AppCatalog { } registry::index_id(&mut index, &def.command.key_text(), at)?; } - Ok(AppCatalog { defs: defs.into(), index: Arc::new(index), generation, replaced: Arc::from([]), typing: None, shown_only: Arc::default() }) + Ok(AppCatalog { defs: defs.into(), index: Arc::new(index), generation, replaced: Arc::from([]), typing: None }) } /// Gives the linked set's command `id` the default chords `bindings` in place of the set's own; an empty list drops @@ -113,26 +111,6 @@ impl AppCatalog { self } - /// Makes the chords of the catalog's commands `ids` shown only: the app dispatches their keys with a keymap of its - /// own. Menu rows, tooltips and buttons still show each command's chord (its bindings, under the overrides, as - /// [`ResolvedCommand::chord`] reads them), but the board passes over the command when it matches a key, as if the - /// command had no binding, so the press fires nothing on the board and stays in egui's input for the app. The - /// command still fires from a menu row, a button, the palette or automation. Later calls add to the earlier ones. - /// An id the linked sets define stays theirs and is ignored here. The board reads the ids every frame, so a change - /// needs no new [`generation`](Self::generation). - #[must_use] - pub fn shown_only>(mut self, ids: impl IntoIterator) -> Self { - let mut shown_only = (*self.shown_only).clone(); - shown_only.extend(ids.into_iter().map(Into::into)); - self.shown_only = Arc::new(shown_only); - self - } - - /// Whether the app dispatches the keys of `command` itself ([`shown_only`](Self::shown_only)). - pub(crate) fn is_shown_only(&self, command: &CommandRef) -> bool { - self.shown_only.contains(command.id.as_str()) - } - /// The default chords the app gives the linked set's command `id`, when it replaced them. pub(crate) fn replaced_defaults(&self, id: &str) -> Option<&[Binding]> { self.replaced.iter().find(|(at, _)| at == id).map(|(_, bindings)| bindings.as_slice()) diff --git a/crates/ui-shell/tests/it/commands/app_catalog.rs b/crates/ui-shell/tests/it/commands/app_catalog.rs index 47055fb799..8b4b271b4c 100644 --- a/crates/ui-shell/tests/it/commands/app_catalog.rs +++ b/crates/ui-shell/tests/it/commands/app_catalog.rs @@ -2,7 +2,6 @@ //! rules every app command follows, and a frame builds a keymap only for a catalog generation it has not built. // The catalog is given through `Frames::commands`, which keeps it for every later frame. -use craft_ui::buttons::{Button, ButtonChord}; use craft_ui::contract::{Bind, Props as _, Show as _, Tracked}; use craft_ui::runtime::commands::{ AppCatalog, Binding, CommandDef, CommandInput, CommandKind, CommandRef, CommandState, CommandStates, EditCommands, FirePhase, Scope, @@ -100,37 +99,6 @@ fn an_app_catalog_command_fires_by_its_chord_and_a_focused_text_field_keeps_a_ty assert_eq!(*name.borrow(), "q", "the focused field types the letter"); } -/// A catalog command whose chord is shown only (`AppCatalog::shown_only`), as a tool whose key the app's own keymap -/// dispatches: a button bound to it shows the chord, and a press of the chord fires nothing on the board and stays in -/// egui's input, where the app reads it. -#[trial] -fn a_shown_only_chord_shows_on_its_button_and_its_press_stays_in_the_input_unfired() { - let key_in_input = Cell::new(false); - let mut show = |ui: &mut Ui| { - AppShell::new(WindowKey::main()) - .body(|ui, _, _| { - let _ = Button::command(CommandRef::new(BRUSH)).chord(ButtonChord::Trailing).show(ui); - if ui.input(|input| input.key_pressed(Key::J)) { - key_in_input.set(true); - } - }) - .show(ui, &mut ()); - }; - let brush = def(BRUSH, "Brush", "J").with_kind(CommandKind::Tool { group: None }); - let mut frames = Frames::new(); - frames.commands(CommandInput::new().catalog(AppCatalog::new(vec![brush], 1).expect("the trial's catalog is valid").shown_only([BRUSH]))); - frames.idle(3, &mut show); - let painted: String = frames.texts().iter().map(|text| text.text.as_str()).collect(); - let (label, chord) = (painted.find("Brush"), painted.rfind('J')); - assert!(label.is_some() && label < chord, "the button shows the shown-only chord after its label: {painted:?}"); - - let _ = fired(&frames); - frames.frame(vec![key_press(Key::J, Modifiers::NONE)], &mut show); - assert!(key_in_input.get(), "the press stays in egui's input for the app's keymap"); - frames.frame(vec![key_release(Key::J, Modifiers::NONE)], &mut show); - assert!(fired(&frames).is_empty(), "the board fires nothing for a shown-only chord"); -} - /// A key's press and its release fire with the input times they arrived at, whichever frame runs them: a hold is /// read from the key's own times. Keys behind a pointer press wait for the next frame (one press per pass) and keep /// the time they arrived at. diff --git a/docs/contract-api.md b/docs/contract-api.md index 450a393de2..7c4c877d99 100644 --- a/docs/contract-api.md +++ b/docs/contract-api.md @@ -3660,7 +3660,6 @@ The command board: the registry and typed sets, per-frame state, the queue, firi - `pub fn new(defs: Vec, generation: u64) -> Result`. A catalog of `defs`; `generation` changes when the app's rows do. Refuses two defs with one id (`Duplicate`) and a - `pub fn replace_defaults(mut self, id: impl Into, bindings: Vec) -> Self`. Gives the linked set's command `id` the default chords `bindings` in place of the set's own; an empty list drops - `pub fn typing_rule(mut self, rule: TypingRule) -> Self`. Sets which chords fire while a text component has the keyboard. The keymap's default, - - `pub fn shown_only>(mut self, ids: impl IntoIterator) -> Self`. Makes the chords of the catalog's commands `ids` shown only: the app dispatches their keys with a keymap of its - `pub fn generation(&self) -> u64`. The app's version of the catalog. The board rebuilds the keymap when it differs from the last frame's, and never - `pub fn defs(&self) -> &[CommandDef]`. The catalog's rows in the order the app gave them, each with its scope (always [`Scope::app`]), kind and - `craft_ui::runtime::commands::CommandGate`: `pub struct CommandGate`. The app's one gate over commands: a dialog is open, a workspace is not ready, a recorder has the keys or an