Skip to content

Fix stuck hold-actions when modifiers change before key release#8097

Open
MadeByGabe wants to merge 1 commit into
beyond-all-reason:masterfrom
MadeByGabe:pr/fix-modified-key-release
Open

Fix stuck hold-actions when modifiers change before key release#8097
MadeByGabe wants to merge 1 commit into
beyond-all-reason:masterfrom
MadeByGabe:pr/fix-modified-key-release

Conversation

@MadeByGabe

Copy link
Copy Markdown
Contributor

actionHandler:KeyAction built its release dispatch from the engine-provided actions which the engine recomputes from the current modifier state at release time.

Let's consider a modified bind (e.g. Shift+n): If I released n while still holding shift, the engine's release dispatch contained shift+n and the release handler ran since it was registered to shift+n.
But if I released Shift first, only then released n, the engine's release dispatch contained only n and the release handler never ran since the handler was expecting shift+n.
The action was stuck in its hold state.
Same if we changed the modifiers for example by alt-tabbing away, or by simply holding ctrl then releasing shift, etc...

Work done

Capture the action list each key triggers at press time(keyed by scancode), and use those on release.
The engine's list is used only as a fallback when nothing was captured.

Test steps

  • Bind for example Shift+sc_n commandinsert prepend_between
  • Queue commands whilel holding shift+n.
  • Release shift, then release n. Commandinsert mode should exit. Without this fix it would stay in insert mode.

I tested all widgets which register hold-style actions, the only issue I found was with gui_overview_cam_tab_hold.lua which doesn't work as expected but not because of this fix, it doesn't work correctly without the fix either (neither gui_overview_keep_camera_position.lua though that's unrelated).

Relevant other PR: #7994

I'm not 100% confident in this fix, I don't know if there are any other edge cases that could cause issues, or that I even understand the engine's behavior well enough to be sure this is a complete/correct fix.

AI / LLM usage statement:

Claude Opus 4.8 validated my reasoning and fix.

Key-release actions are dispatched from the engine's https://github.com/beyond-all-reason/RecoilEngine/blob/2186ee490c027eb2993ce2f67b98d4978ded142e/rts/System/SpringApp.cpp#L1175-L1180, but the engine resets the modifier states before emitting the key up.
For a modified bind (e.g. Shift+key), if the modifiers no longer match at release time the bound action never gets into that list and its release handler never runs.

Capture the actions each physical key triggers at press time (keyed by scancode) and dispatch those on release, independent of the modifier state. Fall back to the engine list only when nothing was captured, preserving existing behaviour.

Fixes CommandInsert getting stuck in insert mode on 'Shift+key' binds beyond-all-reason#7994
@github-actions

Copy link
Copy Markdown
Contributor

Integration Test Results

14 tests  ±0   6 ✅ ±0   3s ⏱️ ±0s
 1 suites ±0   8 💤 ±0 
 1 files   ±0   0 ❌ ±0 

Results for commit 7435e5b. ± Comparison against base commit 2926441.

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