Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(web): encode shifted characters correctly in the terminal (#7485)
Chris Deeming18f6d034897d
diff --git a/apps/web/src/terminal/ghostty/core.ts b/apps/web/src/terminal/ghostty/core.tsindex 022ad038c..227500756 100644--- a/apps/web/src/terminal/ghostty/core.ts+++ b/apps/web/src/terminal/ghostty/core.ts@@ -1,5 +1,6 @@import {type GhosttyKeyboardLayoutMap,+ ghosttyConsumedMods,ghosttyKeyForCode,ghosttyUnshiftedCodepoint,loadGhosttyKeyboardLayoutMap,@@ -464,7 +465,11 @@ export class GhosttyTerminalCore {(event.getModifierState("CapsLock") ? 1 << 4 : 0) |(event.getModifierState("NumLock") ? 1 << 5 : 0);this.runtime.call("ghostty_key_event_set_mods", this.keyEvent, mods);- this.runtime.call("ghostty_key_event_set_consumed_mods", this.keyEvent, 0);+ this.runtime.call(+ "ghostty_key_event_set_consumed_mods",+ this.keyEvent,+ ghosttyConsumedMods(event),+ );this.runtime.call("ghostty_key_event_set_composing", this.keyEvent, event.isComposing ? 1 : 0);this.runtime.call("ghostty_key_event_set_unshifted_codepoint",diff --git a/apps/web/src/terminal/ghostty/keyCodes.test.ts b/apps/web/src/terminal/ghostty/keyCodes.test.tsindex d6fc0cca4..ef4b623fd 100644--- a/apps/web/src/terminal/ghostty/keyCodes.test.ts+++ b/apps/web/src/terminal/ghostty/keyCodes.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vite-plus/test";-import { ghosttyKeyForCode, ghosttyUnshiftedCodepoint } from "./keyCodes";+import { ghosttyConsumedMods, ghosttyKeyForCode, ghosttyUnshiftedCodepoint } from "./keyCodes";describe("ghosttyKeyForCode", () => {it("keeps the tail of the pinned Ghostty key enum in order", () => {@@ -11,6 +11,18 @@ describe("ghosttyKeyForCode", () => {});});+describe("ghosttyConsumedMods", () => {+ const shifted = { altKey: false, ctrlKey: false, key: "@", metaKey: false, shiftKey: true };++ it("only consumes a lone Shift producing a character", () => {+ expect(ghosttyConsumedMods(shifted)).toBe(1);+ expect(ghosttyConsumedMods({ ...shifted, ctrlKey: true })).toBe(0);+ expect(ghosttyConsumedMods({ ...shifted, key: "Tab" })).toBe(0);+ // Deliberate: Shift+Space collapses to Space so it still types one.+ expect(ghosttyConsumedMods({ ...shifted, key: " " })).toBe(1);+ });+});+describe("ghosttyUnshiftedCodepoint", () => {it("provides the logical base character for Kitty keyboard encoding", () => {expect(ghosttyUnshiftedCodepoint({ code: "KeyC", key: "c", shiftKey: false })).toBe(diff --git a/apps/web/src/terminal/ghostty/keyCodes.ts b/apps/web/src/terminal/ghostty/keyCodes.tsindex a82c748b2..a643827d6 100644--- a/apps/web/src/terminal/ghostty/keyCodes.ts+++ b/apps/web/src/terminal/ghostty/keyCodes.ts@@ -233,6 +233,15 @@ export function loadGhosttyKeyboardLayoutMap(): Promise<GhosttyKeyboardLayoutMapreturn promise;}+// Browsers do not expose consumed modifiers; treat Shift as consumed for+// unchorded character input.+export function ghosttyConsumedMods(+ event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "key" | "metaKey" | "shiftKey">,+): number {+ if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return 0;+ return [...event.key].length === 1 ? 1 : 0;+}+export function ghosttyUnshiftedCodepoint(event: Pick<KeyboardEvent, "code" | "key" | "shiftKey">,layoutMap?: GhosttyKeyboardLayoutMap,