Fix markdown/browser Cmd zoom on non-US keyboard layouts

Merged
AU
4mo ago
+112-2

Problem

The markdown viewer's zoom shortcuts (Cmd-= zoom in, Cmd-- zoom out, Cmd-0 reset) from #5163 do not work on European / non-US keyboard layouts (German QWERTZ, French AZERTY, Nordic). A European user cannot trigger markdown zoom from the keys they would naturally press. Browser zoom (browserZoomIn/Out/Reset) has the same defect. Terminal panes still zoom because Ghostty does its own layout-aware font zoom, which is why only the markdown viewer was reported.

Root cause

Markdown and browser zoom both resolve through the unified ShortcutStroke matcher in Sources/KeyboardShortcutSettings.swift. Its symbol normalization (normalizedShortcutEventCharacter) mapped + -> = and _ -> - only when Shift was held (applyShiftSymbolNormalization).

That gate is US-centric. On US layouts +/- only exist as the Shift variants of the =/- key, so requiring Shift was fine. On European layouts + and - are dedicated keys typed WITHOUT Shift: the event reports character +/- with no Shift flag and a keyCode that is not US kVK_ANSI_Equal (24) / kVK_ANSI_Minus (27). So the normalization never ran, the layout-character fallback (also passing applyShiftSymbolNormalization: false) failed, and the final ANSI keyCode fallback compared against US physical keycodes that the +/- keys do not sit on. Net: Cmd-+ / Cmd-- from a European keyboard never matched the =/- zoom chord.

This is the same class of bug a dedicated browserZoomShortcutAction once handled (#680) before shortcuts became configurable and that path was removed.

Fix

Move the + -> = and _ -> - normalization out of the Shift gate so it runs unconditionally in the shared matcher. A bare +/_ can only originate from a dedicated key on a non-US layout (it requires Shift on US), and no shortcut key is ever stored as +/_, so the mapping is always safe and US behavior is unchanged. Because the fix lives in the one matcher every configurable shortcut flows through, it repairs markdown zoom, browser zoom, and any other =/- symbol chord at once, and it follows the actually-bound key so user rebindings are respected. Keypad plus/minus (character +/-) are now covered too.

No new or renamed shortcuts, so Settings UI and docs are unchanged.

Tests

Two-commit red/green structure per repo policy:

  1. Adds matcher tests in cmuxTests/KeyboardShortcutContextTests.swift that simulate the dedicated +/- keys (character +/-, no Shift, non-24/27 keyCode, layout provider returning +/-) and assert they match markdownZoomIn/Out AND browserZoomIn/Out. Plus a guard that a bare letter key does not match the zoom chord. This commit is red.
  2. The fix. This commit is green.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


[!NOTE]
Low Risk
Localized change to keyboard event character normalization with regression tests; no auth, data, or API surface changes.

Overview
Fixes markdown and browser zoom (Cmd-= / Cmd--) on non-US keyboards by changing shared shortcut matching in normalizedShortcutEventCharacter.

+ → = and _ → - now run before the Shift-only symbol normalization. On layouts where + and - are dedicated keys without Shift, events no longer fail to match zoom chords stored as = and -. US behavior stays the same because those symbols still map correctly when Shift is used.

Adds regression tests that simulate European dedicated +/-/_ keys (non-US key codes, no Shift) for markdown and browser zoom, plus a guard that unrelated keys do not match zoom-in.

Reviewed by Cursor Bugbot for commit c7eb1275e91a0cf865a9859de585f54836ff7be6. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fix markdown and browser zoom shortcuts on non‑US keyboards by normalizing '+' and '_' to their base '=' and '-' keys regardless of Shift. Users on German, French, and Nordic layouts can use Cmd-+ and Cmd-- to zoom; keypad +/- also work.

  • Bug Fixes
    • Normalize + -> = and _ -> - unconditionally in the shared ShortcutStroke matcher.
    • Restore Cmd-+/Cmd-- matching for markdown and browser zoom; US behavior unchanged.
    • Add regression tests for dedicated plus/minus keys, bare _ normalization, and a guard against unrelated keys.

Summary by CodeRabbit

  • Bug Fixes

    • Keyboard zoom in/out shortcuts now correctly recognize "+" and "-" (and dedicated "_" where appropriate) on non-US European layouts (e.g., German QWERTZ, AZERTY, Nordic), so zoom shortcuts work as expected on those keyboards.
  • Tests

    • Added regression tests covering non-US layout behavior and an edge-case guard to prevent unrelated key matches.