fix: require a modifier key for keyboard shortcut recording
Description
The keyboard shortcut recorder in handleShortcutKeyDownEvent (Sources/Fluid/ContentView.swift) currently accepts a bare key with no modifier (e.g. pressing F alone, keyCode 3) as a valid global hotkey. Once saved, that key is intercepted system-wide by the app's global event monitor, breaking normal typing of that key in every other app, with no UI path to remove the offending shortcut.
The mouse-click recorder already guards against this exact class of bug (isUnmodifiedLeftOrRightClick → "needs a modifier key"). This PR adds the equivalent guard for keyboard shortcuts.
Design note — the .function flag subtlety: a naive relevantModifierFlags.isEmpty check is not enough. macOS auto-sets the .function modifier flag on key events for function-section keys (arrows, F1–F20, Home/End/Page Up/Page Down, Forward Delete) even when the Fn key is not held — and the global event tap maps .maskSecondaryFn back to .function the same way, so a bare arrow key recorded under that check would still be intercepted system-wide. The guard therefore lives on the model as HotkeyShortcut.isUnmodifiedKeyboardKey (the keyboard analogue of isUnmodifiedLeftOrRightClick): it ignores the auto-injected .function flag for function-section key codes, while still honoring a genuine Fn chord on typing keys (e.g. Fn+F) and excluding modifier-only shortcuts (e.g. Right ⌥), which are legitimate.
The cancel shortcut is exempt: the global tap only consumes it while dictation is running or a cancel callback handles it (GlobalHotkeyManager), and it legitimately defaults to a bare Escape.
Type of Change
- [x] 🐞 Bug fix
- [ ] ✨ New feature
- [ ] 💥 Breaking change
- [ ] 🧹 Chore
- [ ] 📝 Documentation update
Related Issue or Discussion
Closes #556
Testing
My environment has Xcode Command Line Tools only (no full Xcode), so I could not run xcodebuild or the XCTest suite locally, and swiftlint --strict fails locally for lack of sourcekitd. This PR stays in draft so the repo's Build and Test CI can confirm compilation, lint, and tests before it's marked ready for review.
What was verified locally:
Sources/Fluid/Models/HotkeyShortcut.swiftcompiles standalone withswiftcagainst the macOS SDK, and a 15-assertion harness exercisingisUnmodifiedKeyboardKey(bare letters/Space rejected; ⌘F and genuine Fn+F accepted; bare arrows/F5/Home/Forward Delete rejected despite their auto-injected.functionflag; ⇧+arrow accepted; modifier-only and mouse shortcuts excluded) passes in full.- Unit tests covering the same cases were added to the existing
Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swiftfor CI to run; the file passesswiftc -parse. swiftformat --lintreports byte-identical findings on the touched files before and after the change (all pre-existing elsewhere in the files) — no new formatting issues introduced.- Every symbol the ContentView hunk touches was verified against the current source and mirrors the neighboring mouse-shortcut guard.
Screenshots / Video
- [x] No UI/visual changes; screenshots/video are not applicable.
This changes rejection behavior of an existing recorder, not any visual layout — the same "needs a modifier key" message/style the mouse recorder already shows is reused as-is.
Notes
Open question for maintainers: as implemented, bare F-keys (F1–F20) are rejected along with bare typing keys, arrows, and navigation keys — consistent with the PR title, and matching how the .function flag actually behaves (an earlier revision of this PR believed bare F-keys were blocked while arrows were the open question; the auto-injected .function flag made the opposite true). If you'd prefer to allow bare F-keys as global shortcuts (they collide less with normal typing than letters or arrows), it's a one-line change: drop the F-key codes from HotkeyShortcut.functionSectionKeyCodes so their .function flag counts as a real modifier again. Happy to adjust.
Possible follow-up (out of scope here): users who already saved a modifier-less shortcut before this fix still have it persisted in settings (and it survives backup/restore). They can now recover by re-recording, but a one-time sanitization on settings load that strips modifier-less keyboard shortcuts for non-cancel targets would auto-heal existing installs. Can open a separate issue/PR if wanted.
The PR Policy check is blocking this PR because required template information is missing.
Please update the PR description with:
- Testing
Visual files detected:
Sources/Fluid/ContentView.swift
Screenshots or video are required for UI, UX, settings, onboarding, overlay, menu bar, or visual behavior changes. If this PR has no visual changes, check the no-visual-change box in the template.
If this remains incomplete for 48 hours after opening, the PR may be closed.
I think it's on purpose and our uses love to add any key to the system. Since it's optional, it's within your control to decide what key to use. More freedom is better than less freedom :)
This pull request has been marked stale because it has had no activity for 5 days. It will be closed in 2 days if there is no further activity. Add the keep-open or pinned label to prevent automatic closure.
Closing this pull request because it remained inactive for 2 days after being marked stale.