Skip to content

Rebuild the hotkey lookup whenever bindings change - #3082

Merged
sprunk merged 2 commits into
beyond-all-reason:masterfrom
burnhamrobertp:bug/hotkeymap-rebuild-on-mutations
Jul 21, 2026
Merged

Rebuild the hotkey lookup whenever bindings change#3082
sprunk merged 2 commits into
beyond-all-reason:masterfrom
burnhamrobertp:bug/hotkeymap-rebuild-on-mutations

Conversation

@burnhamrobertp

Copy link
Copy Markdown
Contributor

The reverse "action -> keys" lookup (what Spring.GetActionHotKeys and the command-icon hotkey labels use) can be stale, because it's only rebuilt at the tail of ExecuteCommand. At startup the default and user bindings are loaded by Game.cpp calling LoadDefaults() and Load() directly, which skip that path, so the cache sits empty until the first keybinding command runs. Checked in a local build: GetActionHotKeys("pause") returns nothing at boot and is populated after any command. It doesn't surface in BAR because its cmd_bar_hotkeys widget does a keyreload on load, which rebuilds the cache.

This tracks whether bindings actually changed (hotkeysDirty, set on real bind/unbind/etc.) and rebuilds the cache once at the end of the outermost operation when something changed, so LoadDefaults()/Load() now refresh it on their own and the startup gap is gone. As a side effect it also stops the needless rebuild on commands that change nothing (keydebug, redundant binds).

Verified with a small game: GetActionHotKeys("pause") is now correct at startup, and a normal bind still updates it.

This came out of review on #3081 (the KeyBindingsChanged callin), where badosu pointed out the cache should be rebuilt whenever bindings change. It's a pre-existing issue independent of that PR, so it's split out here. The two touch the same spot in ExecuteCommand, so whichever lands second will have a small conflict, and the hotkeysDirty flag is the accurate "did anything change" signal that #3081's event could later use instead of its own.

Used Claude to help with this.

Comment thread rts/Game/UI/KeyBindings.cpp Outdated
@burnhamrobertp
burnhamrobertp force-pushed the bug/hotkeymap-rebuild-on-mutations branch from 61939bb to adb8914 Compare July 8, 2026 20:14
@burnhamrobertp
burnhamrobertp requested a review from sprunk July 8, 2026 20:15
…uild-on-mutations

# Conflicts:
#	rts/Game/UI/KeyBindings.cpp
@sprunk
sprunk merged commit a23be68 into beyond-all-reason:master Jul 21, 2026
3 checks passed
@burnhamrobertp
burnhamrobertp deleted the bug/hotkeymap-rebuild-on-mutations branch July 21, 2026 13:53
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.

2 participants