Fix deleted modifier-only primary shortcuts staying active( #498 )
Summary
Fixes #498.
Clears stale Primary Dictation hotkey press state when the primary shortcut list changes. This prevents a deleted modifier-only primary shortcut from keeping a pending hold/tap path active until app restart.
Changes
- Track removed primary shortcuts in
updatePrimaryShortcuts(_:). - Clear/cancel matching primary dictation runtime state for removed primary shortcuts.
- Keep event tap teardown as a force-clear path.
- Add a regression test for deleting a modifier-only primary shortcut while its hold start is pending.
Testing
Local:
swiftformat --config .swiftformat Sources/Fluid/Services/GlobalHotkeyManager.swift Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
swiftformat --lint --config .swiftformat Sources/Fluid/Services/GlobalHotkeyManager.swift Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
git diff --check
xcrun swiftc -parse Sources/Fluid/Services/GlobalHotkeyManager.swift Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
swiftlint --strict --config .swiftlint.yml
GitHub Actions, same head c2caabd26d8c2a50daa6f061e78449aa233d8d5e:
- Passing fork CI: https://github.com/Yaomeng1749/FluidVoice/actions/runs/28551228981
- Passed: SwiftLint, dependency resolution, build, tests.
Upstream Actions are awaiting maintainer approval for the public-fork workflow.
Final verification for c2caabd26d8c2a50daa6f061e78449aa233d8d5e:
- Added a regression test for deleting a modifier-only Primary Dictation shortcut while its hold start is pending.
- Local Xcode 26.6:
swiftlint --strict --config .swiftlint.ymlpassed with 0 violations. - Fork CI on the same head passed: https://github.com/Yaomeng1749/FluidVoice/actions/runs/28551228981
- CI covered SwiftLint, dependency resolution, build, and tests.
- Upstream Actions are still waiting for maintainer approval for the public-fork workflow.
Thanks for the PR. Actually, very useful PR, and thanks for finding the bug as well, but I think there is one comment that I have for you. Let me know what you think. If you think this is valid, then you can probably fix it for me and then you can merge it .
"active primary press matching only uses keyCode/button. If two primary shortcuts share the same key/button with different modifiers, deleting the inactive one can clear the active held one, so release may not stop recording. Fix: store/compare the active HotkeyShortcut including modifiers."
Thanks, I think this is valid.
The current cleanup path identifies the active primary press by key/button only, which is fine for pairing the release event, but too broad for deciding whether a removed shortcut is the active one. With two primary shortcuts sharing the same key/button but different modifiers, removing the inactive one could clear the active press.
I’ll update the active primary press state to keep the matched HotkeyShortcut and use that full shortcut, including modifiers, when comparing against removed shortcuts. I’ll keep the release path tolerant of modifier changes on key-up, but make the removal cleanup use the full shortcut identity. I’ll also add a regression test for the shared key/button + different modifiers case.
Implemented this in 55a469d2946f3c0f8d2837476cb4aa4731afb2b0.
The active primary press now snapshots the matched shortcut identity, including modifiers, for removal matching. Key-up / mouse-up still only match the released key/button so releasing modifiers before the main key remains supported.
I also added a regression test for the shared-key case: Command+K active, Option+K removed. The active press is preserved and the later K release clears it.
Local checks:
swiftformat --lint --config .swiftformat Sources/Fluid/Services/GlobalHotkeyManager.swift Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swiftgit diff --checkxcrun swiftc -parse Sources/Fluid/Services/GlobalHotkeyManager.swift Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swiftswiftlint --strict --config .swiftlint.yml- targeted
xcodebuild testforFluidDictationIntegrationTests/GlobalHotkeyManagerShortcutTests: 2 passed, 0 failed on macOS/My Mac.
Thanks for the PR. Actually, very useful PR, and thanks for finding the bug as well, but I think there is one comment that I have for you. Let me know what you think. If you think this is valid, then you can probably fix it for me and then you can merge it .
"active primary press matching only uses keyCode/button. If two primary shortcuts share the same key/button with different modifiers, deleting the inactive one can clear the active held one, so release may not stop recording. Fix: store/compare the active HotkeyShortcut including modifiers."
Hi, just following up on this. I updated the PR after your review comment and added the shared-key/different-modifiers regression test. The latest head is 55a469d, and PR Policy is passing. Could you take another look when you have a chance?