Fix terminal zoom on non-US ISO keyboard layouts

ON
2mo ago
+207-8

Summary

On Swedish (and other non-US ISO) layouts, pressing ⌘+ in a focused terminal pane fires zoom-out instead of zoom-in. The + key on Swedish sits at the physical position of US - (keyCode 27), so US-keycode-based matchers route the keystroke to the wrong action.

This PR fixes it at three layers:

  1. AppDelegate.swift — main fix. When a zoom shortcut is detected and the terminal owns first responder, cmux was forwarding the raw NSEvent to Ghostty. Ghostty's internal keybind matcher then resolved the event by US-layout keycode, mis-firing decrease_font_size on Swedish ⌘+. Instead, dispatch the action by name via ghostty_surface_binding_action using the result of the already-layout-aware browserZoomShortcutAction helper.

  2. KeyboardShortcutSettings.swift — matches. The ANSI-keycode fallback fired unconditionally for symbol command shortcuts, masking the typed ASCII character even when it clearly didn't match the bound shortcut key. Letter shortcuts already required a character match in that case; symbol shortcuts now do too. Non-Latin layouts still fall back to US keycodes (hasEventChars && !eventCharsAreASCII) so ⌘W remains reachable on Cyrillic/etc.

  3. KeyboardShortcutSettings.swift — normalizedShortcutEventCharacter. "+" → "=" and "_" → "-" were gated on applyShiftSymbolNormalization. On Swedish (and similar ISO layouts) + is typed without shift, so the gate left the typed "+" un-mapped and Cmd++ could not match the zoom-in binding stored as "=". These two mappings are now unconditional; nothing binds to literal +/_ so there is no conflict.

Test plan

  • New KeyboardShortcutLayoutTests (9 tests, all passing):
    • Swedish ⌘+ matches .browserZoomIn and does not match .browserZoomOut
    • Swedish ⌘_ maps to .browserZoomOut
    • US ⌘=, ⌘⇧= (typed as +), ⌘− baselines preserved
    • Russian ⌘W still resolves via US-keycode fallback (non-ASCII typed char)
    • Anti-regression: an unrelated ASCII char at the same physical position does not match through the keycode fallback
  • Manual test on a Swedish ISO keyboard:
    • ⌘+ in a terminal pane zooms in
    • ⌘− zooms out
    • ⌘0 resets

Fixes #3362
Refs #1456

🤖 Generated with Claude Code


Summary by cubic

Fixes terminal zoom shortcuts on non‑US ISO layouts (e.g., Swedish). Cmd + now zooms in (not out) when a terminal pane is focused.

  • Bug Fixes
    • Route zoom shortcuts to Ghostty by action name using the layout‑aware browserZoomShortcutAction, instead of forwarding raw NSEvent.
    • Require a character match for Command symbol shortcuts before falling back to US ANSI keycodes; non‑Latin layouts still use the fallback.
    • Normalize "+"→"=" and "_"→"-" unconditionally so stored zoom bindings match on layouts where "+" is unshifted.
    • Added KeyboardShortcutLayoutTests covering Swedish ⌘+, US baselines, and Russian ⌘W.

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard shortcut detection across international keyboard layouts (Swedish, Russian, etc.)
    • Fixed font zoom keyboard shortcuts in the terminal to function correctly across different layouts
    • Enhanced keyboard event matching to ensure shortcuts work reliably regardless of physical keyboard configuration

Review Change Stack