Keymap::shown_chord ran a lookup for each single-press binding of the
command, and Board::resolve calls it for every command it resolves, so
each frame repeated those lookups for every command row, tool and button.
The keymap works out each command's shown chord when it is built and
whenever its bindings change, and shown_chord reads the table. The lookup
and the table share one ranking (Keymap::winners), which replaces the
separate press_runs copy of it.
Two costs every frame paid, found in a profile of PhotoCraft on the
framework (storytold/photocraft#15493):
- `MenuBarUi::show` collected the Help search's entries (every row of
every menu, with English labels) on every pass whenever the bar had a
Help menu, open or not. `MenuHelp::built` takes a builder the bar runs
only in a pass that shows the Help menu; `MenuHelp::new` keeps taking a
ready list.
- `Keymap::shown_chord`, which every menu row, tooltip and button asks
each pass, built the command's key string for every `find` and ran a
full `lookup` per binding, cloning the winning commands only to look
their keys up again. `find` now looks up a command without parameters
by its id, and `press_runs` decides on catalog positions. Answers are
unchanged; a new test covers tools sharing a chord (a cycle within a
group, the first of two groups), which no test covered.
Measured in PhotoCraft (Windows 11, idle machine, three runs, together
with PhotoCraft's own storytold/photocraft#15496): UI pass with a pointer
over the canvas 8.7-11.3 ms -> 4.9-5.0 ms, during a menu hover
9.2-10.2 ms -> 6.7-7.1 ms.
Part of storytold/photocraft#15493.
reset, and an edit that leaves a command with its defaults, removed
only the entry the command read. A variant of its key
(window.panel { "panel": "layers" }) stayed and took effect on the
next load. Both remove every entry that resolves to the command.
conflicts_with lists the commands that share one command's chords, with
that command as a, without filtering every conflict. The README shows
set_bindings with one binding for an editor with one shortcut per
command; assign adds a binding.
Apps that stored { command: text } before read the field in older builds
again. Overrides with several bindings for a command still serialize as
the { command, keys } array. keymap::overrides_list always writes the
array, for craft-settings files, where only an array lets a reset entry
leave the file.
craft-keymap holds the data and logic for keyboard bindings: egui-free
chords with one canonical text form, bindings to commands with params,
several bindings per command, scopes, tool groups, conflicts, overrides
kept in a craft-settings type, an import pipeline for other applications'
shortcut sets, and an optional egui dispatcher. Apps keep their command
catalogue, file readers and UI.