Skip to content

fix(shortcuts): accept bare Return as a macOS shortcut key - #183

Merged
haritabh-z01 merged 1 commit into
amicalhq:mainfrom
MaxFreedomPollard:fix/macos-return-keycode-shortcut-validation
Sep 20, 2026
Merged

haritabh-z01 merged 1 commit into
amicalhq:mainfrom
MaxFreedomPollard:fix/macos-return-keycode-shortcut-validation

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

On macOS the Return key sends kVK_Return, which is keycode 36, but MAC_KEYCODES.ENTER in apps/desktop/src/utils/keycodes.ts was 52. So recording Return on its own in the shortcut editor is rejected with "add a modifier", even though bare Space, Tab, Escape and the function keys are all accepted, and Windows accepts its own bare Enter.

Root cause

apps/desktop/src/utils/keycode-map.ts already knows the right answer. Line 52 maps 36: "Enter" and calls it the canonical kVK_Return, keeping 52: "Enter" below it as a legacy alias, and ShortcutManager.swift line 40 declares enterKeyCodes: Set<Int> = [36, 52, 76]. So keycode 36 travels all the way through isKnownKeycode and addActiveKey in apps/desktop/src/main/managers/shortcut-manager.ts and reaches validation as a normal chord.

apps/desktop/src/utils/shortcut-constants.ts was the one place left behind. MAC_SPECIAL_KEYCODES on line 87 listed MAC_KEYCODES.ENTER, which was only 52, so keycode 36 never matched the hasSpecialKey branch of checkAlphanumericOnly in apps/desktop/src/utils/shortcut-validation.ts line 169 and fell through to the addModifier error.

Keypad Enter, keycode 76, was missing for the same reason. keycode-map.ts names it KeypadEnter and shortcut-manager.ts line 610 treats Enter and KeypadEnter alike, and on Windows VK_RETURN covers both the main and numpad keys so WINDOWS_SPECIAL_KEYCODES already accepted numpad Enter. macOS did not.

Fix

MAC_KEYCODES.ENTER is now 36, with ENTER_LEGACY 52 and KEYPAD_ENTER 76 beside it, and MAC_SPECIAL_KEYCODES lists all three. MAC_SPECIAL_KEYCODES was the only consumer of MAC_KEYCODES.ENTER, and the reserved-shortcut tables never referenced it, so changing its value affects nothing else.

Verification

pnpm --filter @amical/desktop test on macOS 26.2 arm64 with Node 24.8.0 and pnpm 10.15.0 gives 119 of 120 files and 1112 of 1113 tests passing. The one failure, tests/vite/posthog-source-maps.test.ts > uses a stable app release and deletes uploaded maps from the bundle, fails identically on main at 14a62ea with nothing of mine applied, so it is not from this change.

The three new assertions in apps/desktop/tests/utils/shortcut-validation.test.ts fail on main and pass with this change. Checking out just the two source files from main and rerunning that file gives 3 failed | 11 passed, with each failure reporting settings.shortcuts.validation.addModifier. The two control cases in the same block, the legacy alias 52 on macOS and VK_RETURN on Windows, pass both before and after, which is what pins this to the missing keycodes rather than to the check itself.

pnpm --filter @amical/desktop type:check reports no errors, prettier --check reports no changes for the three files, and eslint on the two changed source files is clean.

Summary by CodeRabbit

  • Bug Fixes

    • Improved shortcut handling for macOS Return, legacy Return, and keypad Enter keys.
    • Bare Return shortcuts on macOS are now validated correctly.
    • Enter keys are consistently recognized as special keys without requiring modifiers.
  • Tests

    • Added coverage for Enter and Return key handling across macOS and Windows.

MAC_KEYCODES.ENTER was 52, but the Return key on a Mac keyboard sends
kVK_Return, which is 36. utils/keycode-map.ts already names 36 "Enter"
and calls it the canonical code, keeping 52 as a legacy alias, and the
Swift helper's enterKeyCodes in ShortcutManager.swift is [36, 52, 76].
Only utils/shortcut-constants.ts was left behind: MAC_SPECIAL_KEYCODES
listed 52 alone, so keycode 36 never reached the special-key branch of
checkAlphanumericOnly in utils/shortcut-validation.ts.

The effect is that recording Return on its own in the shortcut editor
fails with "add a modifier", while bare Space, Tab, Escape and the
function keys are all accepted, and Windows accepts its own bare Enter
because WINDOWS_SPECIAL_KEYCODES holds VK_RETURN. Keypad Enter, 76, was
missing for the same reason, so on Windows numpad Enter was accepted
(VK_RETURN covers both keys) and on macOS it was not.

MAC_KEYCODES.ENTER is now 36 with ENTER_LEGACY 52 and KEYPAD_ENTER 76
beside it, and MAC_SPECIAL_KEYCODES lists all three. Nothing else reads
MAC_KEYCODES.ENTER: MAC_SPECIAL_KEYCODES was its only consumer, and the
reserved-shortcut tables never used it.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: b172ee80-76c4-41d3-9d79-7e98bc9e1d85

📥 Commits

Reviewing files that changed from the base of the PR and between 14a62ea and ba05264.

📒 Files selected for processing (3)
  • apps/desktop/src/utils/keycodes.ts
  • apps/desktop/src/utils/shortcut-constants.ts
  • apps/desktop/tests/utils/shortcut-validation.test.ts

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


📝 Walkthrough

Walkthrough

The shortcut utilities now distinguish standard, legacy, and keypad Enter keycodes on macOS. Special-key classification includes all variants, with tests covering macOS and Windows Enter handling.

Changes

Enter keycode handling

Layer / File(s) Summary
Enter keycode definitions and validation
apps/desktop/src/utils/keycodes.ts, apps/desktop/src/utils/shortcut-constants.ts, apps/desktop/tests/utils/shortcut-validation.test.ts
Defines macOS Enter keycodes 36, 52, and 76. Adds the legacy and keypad codes to special-key handling. Adds validation tests for macOS and Windows Enter inputs.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to ba052

macOS Return, legacy Enter, and Keypad Enter can now be used without modifiers in shortcut bindings while preserving Windows Enter behavior. The updated validation coverage supports merge readiness.

Suggested reviewers: haritabh-z01

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: accepting a bare macOS Return key as a shortcut key. It accurately reflects the primary objective of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@haritabh-z01
haritabh-z01 merged commit 4c3ed33 into amicalhq:main Sep 20, 2026
1 check passed
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