Skip to content

UI: one keymap drives every keyboard shortcut - #572

Merged
giswqs merged 3 commits into
mainfrom
feat/issue-562-shortcuts
Oct 19, 2026
Merged

giswqs merged 3 commits into
mainfrom
feat/issue-562-shortcuts

Conversation

@giswqs

@giswqs giswqs commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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 read CommandSpec::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

  • New crates/ui-egui/src/keymap.rs: a Keymap of Bindings (key combination, command id, optional parameters) with the current defaults moved in unchanged. Keys are written Mod+Shift+Z (Mod is Ctrl, or ⌘ on macOS), parsed and written back by Chord, ready for the editor and the export/import file in steps 2 and 3.
  • chrome::shortcuts runs 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.
  • Tooltips and menu rows show the shortcut of the command with its parameters, so a map tool button can show its key once one is bound.
  • Command Search shows each command's shortcut after its location.
  • Help › Shortcuts is generated from the keymap (plus the clipboard and mouse rows).
  • A command's own CommandSpec::key joins 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 on main ("Ctrl+Shift+Z redoes"), passes here.
  • help_shortcuts_lists_the_keymap (smoke): Help › Shortcuts shows Undo's key and the Esc map tool row.
  • keymap unit 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, {} and null parameters.

Verification

  • cargo xtask ci (fmt, clippy, tests, layers) and the wasm32-unknown-unknown build of rustgis-web pass locally.
  • ui_shot of 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 shows Home and Ctrl+= / Ctrl+- after the locations.
  • Found while verifying: engine commands declare Mod+C/X/V for 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).
  • Review: Ctrl+D (duplicate layout element) is again held off while a text field has focus.

Part of #562

Summary by CodeRabbit

  • New Features
    • Keyboard shortcuts now follow the configured keymap, with platform-appropriate shortcut labels shown in menus, command search, and Help.
    • The shortcuts window groups commands and includes clipboard shortcuts.
    • Added shortcuts for zooming and duplicating a selected layout element.
  • Bug Fixes
    • Undo and redo shortcuts now correctly restore and reapply deleted features.
    • Shortcuts that lack Ctrl/Command are ignored while typing; layout duplication is ignored unless an element is selected.
  • Documentation
    • Updated the keyboard shortcuts guide to match the app’s shortcuts.

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).
Comment thread crates/ui-egui/src/keymap.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed all 7 changed files against pr-context/AGENTS.md. I read the diff only and did not build or run anything.

Bugs

  • Clipboard commands become key bindings (medium confidence). Keymap::new (crates/ui-egui/src/keymap.rs:190) adds every registry shortcut whose key is free. The registry declares Mod+C, Mod+X and Mod+V for edit.copy, edit.cut and edit.paste, and DEFAULTS doesn't contain them.
    • Double run: these keys are meant to arrive only as Copy/Cut/Paste events. The new bindings can run the command a second time.
    • Cut or copy while typing: chrome::shortcuts skips only chords without Ctrl while a text field has focus. Ctrl+C or Ctrl+X in a text field could therefore run edit.copy or edit.cut on the selected map features, and cut deletes them.
    • Paste with no text: edit.paste would run without its text parameter.
    • The inline comment suggests excluding these in new and adding a test.
  • Ctrl+D no longer waits for !typing (low–medium confidence). It used to be gated on not typing. It now only needs a selected layout element, so it can fire while a text field has focus.

Security

  • Nothing found.

Performance

  • match_order() allocates and sorts the bindings on every frame, and shortcuts clones each pending command's parameters. These are small, so it is a nit. The sorted order could be cached in Keymap. (low confidence)

Quality

  • Chord::parse relies on egui::Key::from_name for = and -. The Mod+= and Mod+- specs in navigate.rs are parsed this way, and the unit test covers Mod+- but not Mod+=. Add a case for Mod+=.
  • The Help › Shortcuts window now builds a Vec of rows every frame. That is fine.
  • widgets::shortcut_text is a thin wrapper kept for mapview.rs. Consider calling keymap::shortcut_text directly and dropping it.

AGENTS.md

  • User-visible strings are wrapped in tl! in the Shortcuts window, label and the tool names. UI_LABELS is translated only when label looks it up.
  • No unwrap, expect or panic! was added in non-test code. The default-binding parse falls back safely.
  • Nothing platform-specific breaks wasm.
  • I did not check ATTRIBUTION.md or the i18n catalogs because this PR adds no assets.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head 1da9273).

Metric Value
Files changed 7 (1 added, 6 modified, 0 removed, 0 renamed)
Size before 403.4 KB
Size after 417.1 KB
Total size change +13.7 KB
File Before After Change
crates/ui-egui/src/keymap.rs 0 B 11.7 KB +11.7 KB
crates/ui-egui/tests/smoke.rs 98.6 KB 99.8 KB +1.3 KB
crates/ui-egui/src/chrome.rs 48.8 KB 49.2 KB +362 B
docs/user-guide/index.md 9.9 KB 10.2 KB +258 B
crates/ui-egui/src/lib.rs 171.8 KB 172.0 KB +196 B
crates/ui-egui/src/widgets.rs 21.1 KB 21.0 KB -83 B
crates/engine/src/lib.rs 53.1 KB 53.2 KB +74 B

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.
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 59dcbf95-dc3a-46b9-a5bf-7c4546131a27
📥 Commits

Reviewing files that changed from the base of the PR and between 98921c3 and 36e7591.

📒 Files selected for processing: 7
  • crates/engine/src/lib.rs
  • crates/ui-egui/src/chrome.rs
  • crates/ui-egui/src/keymap.rs
  • crates/ui-egui/src/lib.rs
  • crates/ui-egui/src/widgets.rs
  • crates/ui-egui/tests/smoke.rs
  • docs/user-guide/index.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The UI now uses a shared keymap for shortcut parsing, dispatch, and display. The keymap combines default bindings with available command-declared shortcuts. Command Search, shortcut listings, and widget tooltips display configured bindings. Tests and the user guide cover shortcut behavior and labels.

Changes: Configured UI Shortcuts

Layer / File(s) Summary
Keymap contracts and app initialization
crates/engine/src/lib.rs, crates/ui-egui/src/keymap.rs, crates/ui-egui/src/lib.rs
The keymap parses and formats chords, combines default and available registry shortcuts, and initializes from the session registry.
Shortcut dispatch and UI presentation
crates/ui-egui/src/chrome.rs, crates/ui-egui/src/widgets.rs, crates/ui-egui/tests/smoke.rs, docs/user-guide/index.md
Keyboard handling and shortcut displays use keymap bindings. Smoke tests and the user guide cover shortcut behavior and labels.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Keyboard as Keyboard event
  participant Chrome as chrome shortcut dispatch
  participant Keymap as app.ui.keymap
  participant Commands as Command dispatch
  Keyboard->>Chrome: Deliver key event
  Chrome->>Keymap: Read match_order()
  Keymap-->>Chrome: Return ordered bindings
  Chrome->>Commands: Dispatch matching command and parameters
Loading

Suggested reviewers: jgregoriorincon

Merge Risk: ⚪ Minimal · up to 36e75

The examined shortcuts retain their behavior, and no issue remains that needs resolution before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: a shared keymap drives UI keyboard shortcuts.
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 6 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is complete and relevant. It explains the change, root cause, implementation, tests, verification steps, and related issue. It does not use the exact template headings, but all require…
Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 6 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description is complete and relevant. It explains the change, root cause, implementation, tests, verification steps, and related issue. It does not use the exact template headings, but all required information is present.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit taps keys by the moon,
The keymap sorts chords in a tune.
Undo and redo hop through,
Tooltips show shortcuts too,
Then the bunny bounds off at noon.

Comment @coderabbitai help to get the list of available commands.

Comment thread crates/ui-egui/src/chrome.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Posted one inline comment; now writing up the review.

Code review

I read the whole diff and checked the other callers of the changed tooltip signature. I couldn't build or run anything here, so none of this is tested. The change replaces the hard-coded key list with a data-driven Keymap in keymap.rs. It is generally clean and covered by tests. Panics, wasm and layering look fine, with no unwrap/expect.

Bugs

  • Mod+D now fires while a text field has focus (crates/ui-egui/src/chrome.rs:485, inline comment posted). The old code gated Ctrl+D behind !typing. The new loop runs every Ctrl-chord regardless of focus, so a selected layout element can be duplicated from inside a text field. Confidence: medium.

Security

  • Nothing found. Key strings are parsed defensively and Chord::parse returns None on bad input.

Performance

  • Nothing significant. shortcut_text scans about 20 bindings and re-parses the three clipboard chords for each Command Search row on every frame. That is negligible, but you could cache the parsed clipboard chords. Confidence: low.

Quality

  • The "Copy / Cut / Paste features" row in Help › Shortcuts joins the key text, which isn't translated, but the label is translated through tl!. Passing the non-literal k and d to tl! in the loop may not be picked up by the catalog extractor. Confidence: low.
  • DEFAULTS includes Delete → edit.delete, and Backspace is still special-cased in chrome.rs. Part of the key handling therefore stays outside the keymap. Confidence: low.
  • Chord::text and Display handle Plus, Minus and Equals differently (symbol_or_name vs name). That's intentional, and the round-trip test covers it.

AGENTS.md

  • Layering, never-crash and wasm rules appear to be respected. The new interface strings use tl! or i18n::fmt. New catalog entries aren't required.
  • The new tests (ctrl_shift_z_redoes_rather_than_undoing, help_shortcuts_lists_the_keymap, and the keymap unit tests) are good. No regression test covers the typing-focus gating for the new keymap path. Confidence: medium.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head 140eec8).

Metric Value
Files changed 7
Added / modified / removed / renamed 1 / 6 / 0 / 0
Size before 403.4 KB
Size after 418.4 KB
Total size change +15.1 KB
File Before After Change
crates/ui-egui/src/keymap.rs 0 B 12.9 KB +12.9 KB
crates/ui-egui/tests/smoke.rs 98.6 KB 99.8 KB +1.3 KB
crates/ui-egui/src/chrome.rs 48.8 KB 49.4 KB +518 B
docs/user-guide/index.md 9.9 KB 10.2 KB +258 B
crates/ui-egui/src/lib.rs 171.8 KB 172.0 KB +196 B
crates/ui-egui/src/widgets.rs 21.1 KB 21.0 KB -83 B
crates/engine/src/lib.rs 53.1 KB 53.2 KB +74 B

- Ctrl+D (duplicate layout element) is held off while a text field has
  focus again, as before the keymap.
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff and the surrounding chrome::shortcuts code, and checked how CommandSpec shortcuts and RustGisApp construction are used. I found no blocking problems. I couldn't build or run anything, so nothing here is tested. The Ctrl+Shift+Z and Ctrl+Shift+S fix looks correct.

Bugs

  • None found. Sorting bindings so those with more modifiers are matched first does fix the Ctrl+Shift+Z and Ctrl+Shift+S cases. A matched key press is consumed, so the shorter chord can no longer fire on the same event. (high confidence)
  • Behaviour matches the old code on these points: keys without Ctrl/⌘ are skipped while a text field has focus, Ctrl+D needs a selected layout element, the Backspace delete key in layouts is kept, and clipboard events are still handled separately. (medium-high)

Security

  • Nothing found. Keymap input is only compiled-in constants, and Chord::parse returns None for junk. There is no unwrap, expect or panic in the new non-test code, and nothing indexes into a slice. (high)

Performance

  • match_order() allocates and sorts a Vec on every frame, and Command Search calls shortcut_text once per visible row. Both are tiny lists, so I don't expect a visible cost. Caching the sorted order inside Keymap would be a cheap tidy-up later. (low, nit)

Quality

  • The PR description says no command sets CommandSpec::shortcut, and the new doc comment implies the same. In fact edit.delete, project.new, project.save, project.saveAs, edit.undo, layer.remove and map.zoomIn/zoomOut all call .key(...). Those keys are mostly already bound to ui.* equivalents, so Keymap::new skips them. As a result shortcut_text("project.save") and shortcut_text("project.open") are empty, because the binding belongs to ui.save and ui.open. Previously they showed Ctrl+S and Ctrl+O. I found no ribbon or menu button using project.save, project.saveAs or project.open with a tooltip, so I don't expect a visible regression. Please confirm, and consider reporting ui.save to project.save aliases explicitly. (medium-low)
  • The test clipboard_keys_stay_events only checks that layer.remove has no key. A test that Keymap::new gives the same result as Keymap::default plus the free command keys would catch silent behaviour changes if a command later declares a key. (low)
  • Chord::text and Display pick the key name differently: symbol_or_name for Plus, Minus and Equals in text, name() in Display. That is intentional, but a one-line comment on Display saying it must stay parse-compatible would help. (low, nit)
  • tl!(k) and tl!(d) in the Help › Shortcuts rows take non-literal arguments. If the string-extraction tooling only scans literals, the "Mouse wheel" and similar rows will not be picked up for translation. This is a nit, since a missing entry shows in English. (low)

AGENTS.md

  • All new interface text is wrapped in tl! or i18n::fmt. The new code has no unwrap or panic, and keymap.rs stays below the egui-free layers as cargo xtask layers requires. (high)
  • Regression tests are included: ctrl_shift_z_redoes_rather_than_undoing, help_shortcuts_lists_the_keymap and the keymap unit tests. (high)
  • The hostile_params_never_panic command sweep is untouched. Keymap is UI-only and takes no command parameters, so I see no extra exposure. (medium)

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head 36e7591)

Metric Value
Files changed 7 (1 added, 6 modified, 0 removed, 0 renamed)
Size before 403.4 KB
Size after 418.5 KB
Total size change +15.1 KB
File Before After Change
crates/ui-egui/src/keymap.rs 0 B 12.9 KB +12.9 KB
crates/ui-egui/tests/smoke.rs 98.6 KB 99.8 KB +1.3 KB
crates/ui-egui/src/chrome.rs 48.8 KB 49.4 KB +580 B
docs/user-guide/index.md 9.9 KB 10.2 KB +258 B
crates/ui-egui/src/lib.rs 171.8 KB 172.0 KB +196 B
crates/ui-egui/src/widgets.rs 21.1 KB 21.0 KB -83 B
crates/engine/src/lib.rs 53.1 KB 53.2 KB +74 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-572/
Web app https://preview.rustgis.app/pr-572/app/
Commit 36e7591

GitHub Pages takes a minute or two to publish a new commit.

@giswqs
giswqs merged commit d617e24 into main Oct 19, 2026
19 checks passed
@giswqs
giswqs deleted the feat/issue-562-shortcuts branch October 19, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant