Skip to content

fix(web): German Option characters reach the terminal - #76

Closed
macodev00 wants to merge 1 commit into
mainfrom
cursor/german-terminal-option-chars-redo2-bcae
Closed

macodev00 wants to merge 1 commit into
mainfrom
cursor/german-terminal-option-chars-redo2-bcae

Conversation

@macodev00

Copy link
Copy Markdown
Owner

Problem

On a German Mac layout, @ is Option+L. The desktop terminal and the web app share this Ghostty surface, and both forwarded Option as Alt into libghostty-vt. That WASM build is not Darwin, so Ghostty's macos-option-as-alt = false path never runs. DEC 1036 turns Option+L into ESC @ (readline set-mark), so nothing is typed. The same encoding drops the rest of that Option layer (€, ~, []{}|, \).

Electron does not set AltGraph for Option, so the existing AltGr bypass does not apply. Option+arrow word motion is a separate path.

Fixes pingdotgg#13046

Supersedes pingdotgg#14576

Why

Marking Alt consumed still leaves the raw Alt bit set. modifyOtherKeys mode 2 and Kitty report-all read that bit and emit an Alt sequence even when Alt is also consumed. The raw Alt bit has to be cleared when Option composition is consumed. Shift is cleared only when it participated in that composition. A lone Shift stays in the raw mask.

pingdotgg#14576 left navigator.platform unrestored whenever it was inherited. Node exposes platform on the prototype, so saving only an own-property descriptor did nothing and later tests kept the stub. Cleanup now restores a saved own descriptor, and deletes the temporary own property when there was none, inside finally, including when the stubbed call throws.

Change

A lone macOS Option that produces one character is consumed, and those consumed bits are cleared from the raw modifier mask before encoding. Ctrl, Meta, Option+arrow, and a lone Shift stay intact, including Shift+letter under modifyOtherKeys mode 2.

There is no Option-as-Meta setting. This matches Terminal.app with "Use Option as Meta key" off, and Ghostty's default. Option+letter chords that previously became ESC plus the unshifted letter now type the composed character.

Scope and approval

Triaged bug pingdotgg#13046 (accepted by juliusmarminge). The change is the terminal key encoder in the web surface the desktop app embeds. Mobile's native terminal is a different path and is unchanged.

Verification

From commit 4aeae6d73, Node 24.13.1 (v24.13.1).

Formatter, from the repo root:

./node_modules/.bin/vp fmt apps/web/src/terminal/ghostty/keyCodes.ts apps/web/src/terminal/ghostty/keyCodes.test.ts apps/web/src/terminal/ghostty/core.ts apps/web/src/terminal/ghostty/core.test.ts apps/web/src/terminal/ghostty/runtimeAbi.test.ts

Result, exit 0:

note: You are running `vp fmt` as a Vite+ built-in command. If you meant to run the fmt npm script, use `vpr fmt` instead.
Finished in 151ms on 5 files using 4 threads.

No further edits.

Lint, from the repo root:

./node_modules/.bin/vp lint apps/web/src/terminal/ghostty/keyCodes.ts apps/web/src/terminal/ghostty/core.ts apps/web/src/terminal/ghostty/core.test.ts apps/web/src/terminal/ghostty/keyCodes.test.ts apps/web/src/terminal/ghostty/runtimeAbi.test.ts

Result, exit 0. The only warning is the existing no-new-array note in ghosttyCellText:

apps/web/src/terminal/ghostty/core.ts:182:19: warning unicorn(no-new-array): Do not use `new Array(singleArgument)`.

Unit tests, from apps/web:

../../node_modules/.bin/vp test run --project unit src/terminal/ghostty/keyCodes.test.ts src/terminal/ghostty/runtimeAbi.test.ts src/terminal/ghostty/core.test.ts

Result, exit 0:

 RUN  v5.0.1 /workspace/apps/web

 Test Files  3 passed (3)
      Tests  35 passed (35)
   Start at  06:28:55
   Duration  6.11s (transform 52%, import 27%, tests 15%, setup 6%)

Typecheck, from the repo root:

./node_modules/.bin/vp run --filter @t3tools/web typecheck

Result, exit 0:

~/apps/web$ tsc --noEmit ⊘ cache disabled

The WASM tests assert the encoded bytes, not only the consumed-mod bitmask:

  • Default and Kitty disambiguate: raw Alt encodes ESC @ / CSI 64;3 u. Consumed Alt without clearing the raw bit is still an Alt sequence under modifyOtherKeys mode 2 (CSI 27;3;64~). The mask encodeKey sends encodes @.
  • Option+Shift+7 (\): leaving the composing Shift in the raw mask encodes CSI 27;2;92~. Clearing it encodes \.
  • Lone Shift+A under modifyOtherKeys mode 2 stays CSI 27;2;65~.
  • GhosttyTerminalCore.encodeKey on a MacIntel platform writes @, €, |, and \ in the default, modifyOtherKeys, and Kitty disambiguate modes, and the Kitty report-all sequence \x1b[64::108;;64u. Linux and Windows Alt still prefix ESC. Ctrl+C and Option+Left are unchanged.
  • navigator.platform is restored after every encodeKey test. An inherited platform (no own descriptor) is deleted again after a thrown stub, and an own descriptor is put back.

Platform checks and Limitations

Checked on Linux x86_64, Node 24.13.1. In this runtime navigator.platform is the inherited value Linux x86_64, which is the case that previously leaked an own property.

Not checked on a physical German keyboard or Electron on macOS. The assertions pass a platform string into the same encoder the desktop app uses.

Option+letter chords that used to send ESC plus the unshifted letter now type the composed character. There is no setting to keep Option as Meta.

UI Changes

None visual. This changes the bytes the terminal key encoder sends for macOS Option compositions. There is no layout or rendering change to screenshot.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots (none: no visual change)
  • Video for interaction changes (none: the encoded key bytes are asserted directly in tests; no physical German Mac keyboard available)
Open in Web Open in Cursor 

On macOS, Option+L is @. The terminal forwarded Option as Alt into a
non-Darwin libghostty-vt build, so DEC 1036 sent ESC @. Marking Alt
consumed still left the raw Alt bit set, and modifyOtherKeys mode 2
encoded that as an Alt sequence.

Consume a lone macOS Option that produced a character, and clear those
consumed bits from the raw modifier mask before encoding. Ctrl, Meta,
Option+arrow, and a lone Shift stay intact. There is no Option-as-Meta
setting; this matches Terminal.app with that option off.

Tests that stub navigator.platform restore the previous own descriptor,
and delete the temporary own property when platform was inherited,
including when the stubbed call throws.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Oct 2, 2026
@macodev00

Copy link
Copy Markdown
Owner Author

Opened upstream.

@macodev00 macodev00 closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot type @ char in Terminal on MacOS with German Keyboard Layout

1 participant