Repository navigation
UI: one keymap drives every keyboard shortcut - #572
Conversation
The global shortcuts were a fixed table in chrome::shortcuts, and Help › Shortcuts was a second hard-coded list that could drift from it. Tooltips and menus read CommandSpec::shortcut, which no command set. A new keymap module holds the default bindings (key combination, command, parameters). It drives the key handling, the shortcut in tooltips and menu rows (now including commands with parameters, such as a map tool), a new shortcut column in Command Search and the Help › Shortcuts window. A command's own CommandSpec::key joins the defaults where its key is free. Matching tries the bindings with more modifiers first: egui ignores an extra Shift, so Ctrl+Shift+Z ran Undo instead of Redo and Ctrl+Shift+S ran Save instead of Save As. Part of #562 (step 1 of 3).
Code reviewI reviewed all 7 changed files against Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 98921c3 to PR head 1da9273).
|
Copy, Cut and Paste declare Mod+C/X/V, and Keymap::new took them in as key bindings, but those keys arrive as clipboard events, which already run the commands. The keymap now leaves them out; tooltips and Help › Shortcuts still show them.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Posted one inline comment; now writing up the review. Code reviewI read the whole diff and checked the other callers of the changed Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 98921c3 to PR head 140eec8).
|
- Ctrl+D (duplicate layout element) is held off while a text field has focus again, as before the keymap.
Code reviewI read the full diff and the surrounding Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 98921c3 to PR head 36e7591)
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
Step 1 of #562: one source for keyboard shortcuts.
Root cause
The global shortcuts were a fixed table in
chrome::shortcuts, Help › Shortcuts was a second hard-coded list, and tooltips and menu rows readCommandSpec::shortcut, which no command sets. The three could drift apart, and nothing could be customized without editing all of them.While moving the table, a real bug showed up: the keys were matched with egui's
consume_shortcut, which ignores an extra Shift or Alt. Ctrl+Z was checked before Ctrl+Shift+Z, so Ctrl+Shift+Z ran Undo instead of Redo, and Ctrl+S was checked before Ctrl+Shift+S, so Ctrl+Shift+S saved instead of Save As.Fix
crates/ui-egui/src/keymap.rs: aKeymapofBindings (key combination, command id, optional parameters) with the current defaults moved in unchanged. Keys are writtenMod+Shift+Z(Modis Ctrl, or ⌘ on macOS), parsed and written back byChord, ready for the editor and the export/import file in steps 2 and 3.chrome::shortcutsruns the keymap. Bindings with more modifiers are tried first (fixes the two bugs above). Keys without Ctrl/⌘ never fire while a text field has focus, as before. Ctrl+D (duplicate layout element) only takes the key when a layout element is selected, as before; Backspace as the Mac delete key in layouts and the clipboard events stay as they were.CommandSpec::keyjoins the defaults where its key is free, so that field is no longer dead.docs/user-guide/index.md: the shortcut table gains Save As, the second Redo key, zoom in/out and Ctrl+D.Tests
ctrl_shift_z_redoes_rather_than_undoing(smoke): deletes a feature, Ctrl+Z restores it, Ctrl+Shift+Z deletes it again. Fails onmain("Ctrl+Shift+Z redoes"), passes here.help_shortcuts_lists_the_keymap(smoke): Help › Shortcuts shows Undo's key and the Esc map tool row.keymapunit tests: parsing and writing key combinations (Mod++,ctrl+t,Esc, junk), every default parses and no key is bound twice, match order, two keys for Redo,{}andnullparameters.Verification
cargo xtask ci(fmt, clippy, tests, layers) and thewasm32-unknown-unknownbuild ofrustgis-webpass locally.ui_shotof Help › Shortcuts (light and dark) and of Command Search filtered to "zoom": the Help window lists the keymap's keys (Redo with both keys, one Copy / Cut / Paste row), and Command Search showsHomeandCtrl+=/Ctrl+-after the locations.Mod+C/X/Vfor Copy, Cut and Paste, and the first commit took them in as key bindings although they arrive as clipboard events. The keymap now leaves them out and still shows them (clipboard_keys_stay_events).Part of #562
Summary by CodeRabbit