The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 15:15 UTC
fix(web): encode shifted characters correctly in the terminal (#7485)
Chris Deeming committed
Aug 21, 2026 at 06:08 UTC
18f6d034897d9cc5429dcb88c6a9795d183f1687
3 files changed
+28
-2
apps/web/src/terminal/ghostty/core.ts
+6
-1
@@ -1,5 +1,6 @@
1
import {
2
type GhosttyKeyboardLayoutMap,
3
+ ghosttyConsumedMods,
4
ghosttyKeyForCode,
5
ghosttyUnshiftedCodepoint,
6
loadGhosttyKeyboardLayoutMap,
@@ -464,7 +465,11 @@ export class GhosttyTerminalCore {
465
(event.getModifierState("CapsLock") ? 1 << 4 : 0) |
466
(event.getModifierState("NumLock") ? 1 << 5 : 0);
467
this.runtime.call("ghostty_key_event_set_mods", this.keyEvent, mods);
467
- this.runtime.call("ghostty_key_event_set_consumed_mods", this.keyEvent, 0);
468
+ this.runtime.call(
469
+ "ghostty_key_event_set_consumed_mods",
470
+ this.keyEvent,
471
+ ghosttyConsumedMods(event),
472
+ );
473
this.runtime.call("ghostty_key_event_set_composing", this.keyEvent, event.isComposing ? 1 : 0);
474
this.runtime.call(
475
"ghostty_key_event_set_unshifted_codepoint",
apps/web/src/terminal/ghostty/keyCodes.test.ts
+13
-1
@@ -1,6 +1,6 @@
1
import { describe, expect, it } from "vite-plus/test";
2
3
-import { ghosttyKeyForCode, ghosttyUnshiftedCodepoint } from "./keyCodes";
3
+import { ghosttyConsumedMods, ghosttyKeyForCode, ghosttyUnshiftedCodepoint } from "./keyCodes";
4
5
describe("ghosttyKeyForCode", () => {
6
it("keeps the tail of the pinned Ghostty key enum in order", () => {
@@ -11,6 +11,18 @@ describe("ghosttyKeyForCode", () => {
11
});
12
});
13
14
+describe("ghosttyConsumedMods", () => {
15
+ const shifted = { altKey: false, ctrlKey: false, key: "@", metaKey: false, shiftKey: true };
16
+
17
+ it("only consumes a lone Shift producing a character", () => {
18
+ expect(ghosttyConsumedMods(shifted)).toBe(1);
19
+ expect(ghosttyConsumedMods({ ...shifted, ctrlKey: true })).toBe(0);
20
+ expect(ghosttyConsumedMods({ ...shifted, key: "Tab" })).toBe(0);
21
+ // Deliberate: Shift+Space collapses to Space so it still types one.
22
+ expect(ghosttyConsumedMods({ ...shifted, key: " " })).toBe(1);
23
+ });
24
+});
25
+
26
describe("ghosttyUnshiftedCodepoint", () => {
27
it("provides the logical base character for Kitty keyboard encoding", () => {
28
expect(ghosttyUnshiftedCodepoint({ code: "KeyC", key: "c", shiftKey: false })).toBe(
apps/web/src/terminal/ghostty/keyCodes.ts
+9
@@ -233,6 +233,15 @@ export function loadGhosttyKeyboardLayoutMap(): Promise<GhosttyKeyboardLayoutMap
233
return promise;
234
}
235
236
+// Browsers do not expose consumed modifiers; treat Shift as consumed for
237
+// unchorded character input.
238
+export function ghosttyConsumedMods(
239
+ event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "key" | "metaKey" | "shiftKey">,
240
+): number {
241
+ if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return 0;
242
+ return [...event.key].length === 1 ? 1 : 0;
243
+}
244
+
245
export function ghosttyUnshiftedCodepoint(
246
event: Pick<KeyboardEvent, "code" | "key" | "shiftKey">,
247
layoutMap?: GhosttyKeyboardLayoutMap,