Skip to content

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): hide thread jump hints while the terminal is focused (#7277)

Lars Nieuwenhuisce8ca5bb3d00
diff --git a/apps/web/src/components/LegacySidebar.tsx b/apps/web/src/components/LegacySidebar.tsx
index dbfa1babd..b4f3b5996 100644
--- a/apps/web/src/components/LegacySidebar.tsx
+++ b/apps/web/src/components/LegacySidebar.tsx
@@ -73,6 +73,7 @@ import {
import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal";
import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstraps";
import { isElectron } from "../env";
+import { useTerminalFocus } from "../hooks/useTerminalFocus";
import { useOpenPrLink } from "../lib/openPullRequestLink";
import { isTerminalFocused } from "../lib/terminalFocus";
import { isMacPlatform } from "../lib/utils";
@@ -3075,6 +3076,7 @@ export default function LegacySidebar() {
const setSelectionAnchor = useThreadSelectionStore((s) => s.setAnchor);
const platform = navigator.platform;
const shortcutModifiers = useShortcutModifierState();
+ const terminalFocused = useTerminalFocus();
const { environments } = useEnvironments();
const primaryEnvironmentId = usePrimaryEnvironmentId();
const environmentLabelById = useMemo(
@@ -3397,7 +3399,7 @@ export default function LegacySidebar() {
[threadJumpCommandByKey],
);
const sidebarShortcutContext = {
- terminalFocus: false,
+ terminalFocus: terminalFocused,
terminalOpen: routeTerminalOpen,
modelPickerOpen: isModelPickerOpen(),
};
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index d64a6a2b7..a88bc9ce4 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -83,6 +83,7 @@ import {
threadTraversalDirectionFromCommand,
} from "../keybindings";
import { useShortcutModifierState } from "../shortcutModifierState";
+import { useTerminalFocus } from "../hooks/useTerminalFocus";
import { isTerminalFocused } from "../lib/terminalFocus";
import { isModelPickerOpen } from "../modelPickerVisibility";
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
@@ -3312,10 +3313,18 @@ export default function Sidebar() {
// match a thread-jump binding. Adding Shift (screenshots) or Alt no
// longer matches ⌘1..9, so the overlay hides for chords like ⌘⇧4.
const shortcutModifiers = useShortcutModifierState();
+ const terminalFocused = useTerminalFocus();
const shouldShowJumpHintsNow = shouldShowThreadJumpHintsForModifiers(
shortcutModifiers,
keybindings,
- { platform: navigator.platform },
+ {
+ platform: navigator.platform,
+ context: {
+ terminalFocus: terminalFocused,
+ terminalOpen: routeTerminalOpen,
+ modelPickerOpen: isModelPickerOpen(),
+ },
+ },
);
useEffect(() => {
setShowJumpHints(shouldShowJumpHintsNow);
diff --git a/apps/web/src/hooks/useTerminalFocus.test.ts b/apps/web/src/hooks/useTerminalFocus.test.ts
new file mode 100644
index 000000000..60d948741
--- /dev/null
+++ b/apps/web/src/hooks/useTerminalFocus.test.ts
@@ -0,0 +1,42 @@
+import { afterEach, describe, expect, it } from "vite-plus/test";
+
+import { subscribeToTerminalFocusChanges } from "./useTerminalFocus";
+
+const originalWindow = globalThis.window;
+
+afterEach(() => {
+ if (originalWindow === undefined) {
+ delete (globalThis as { window?: Window }).window;
+ } else {
+ globalThis.window = originalWindow;
+ }
+});
+
+describe("subscribeToTerminalFocusChanges", () => {
+ it("notifies on focus transitions until unsubscribed", () => {
+ const listeners = new Map<string, Set<() => void>>();
+ globalThis.window = {
+ addEventListener: (type: string, listener: EventListenerOrEventListenerObject) => {
+ const callbacks = listeners.get(type) ?? new Set<() => void>();
+ callbacks.add(listener as () => void);
+ listeners.set(type, callbacks);
+ },
+ removeEventListener: (type: string, listener: EventListenerOrEventListenerObject) => {
+ listeners.get(type)?.delete(listener as () => void);
+ },
+ } as unknown as Window & typeof globalThis;
+ let notifications = 0;
+
+ const unsubscribe = subscribeToTerminalFocusChanges(() => {
+ notifications += 1;
+ });
+
+ for (const listener of listeners.get("focusin") ?? []) listener();
+ for (const listener of listeners.get("focusout") ?? []) listener();
+ expect(notifications).toBe(2);
+
+ unsubscribe();
+ for (const listener of listeners.get("focusin") ?? []) listener();
+ expect(notifications).toBe(2);
+ });
+});
diff --git a/apps/web/src/hooks/useTerminalFocus.ts b/apps/web/src/hooks/useTerminalFocus.ts
new file mode 100644
index 000000000..84c897ffc
--- /dev/null
+++ b/apps/web/src/hooks/useTerminalFocus.ts
@@ -0,0 +1,16 @@
+import { useSyncExternalStore } from "react";
+
+import { isTerminalFocused } from "../lib/terminalFocus";
+
+export function subscribeToTerminalFocusChanges(listener: () => void): () => void {
+ window.addEventListener("focusin", listener, true);
+ window.addEventListener("focusout", listener, true);
+ return () => {
+ window.removeEventListener("focusin", listener, true);
+ window.removeEventListener("focusout", listener, true);
+ };
+}
+
+export function useTerminalFocus(): boolean {
+ return useSyncExternalStore(subscribeToTerminalFocusChanges, isTerminalFocused, () => false);
+}
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts
index 6ac53a52f..7d07610c6 100644
--- a/apps/web/src/keybindings.test.ts
+++ b/apps/web/src/keybindings.test.ts
@@ -451,6 +451,21 @@ describe("thread navigation helpers", () => {
}),
);
});
+
+ it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {
+ assert.isFalse(
+ shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
+ platform: "MacIntel",
+ context: { terminalFocus: true },
+ }),
+ );
+ assert.isTrue(
+ shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
+ platform: "MacIntel",
+ context: { terminalFocus: false },
+ }),
+ );
+ });
});
describe("model picker navigation helpers", () => {
diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts
index 6ec9a6fab..eb4637df2 100644
--- a/apps/web/src/keybindings.ts
+++ b/apps/web/src/keybindings.ts
@@ -301,6 +301,16 @@ export function shouldShowThreadJumpHintsForModifiers(
keybindings: ResolvedKeybindingsConfig,
options?: ShortcutMatchOptions,
): boolean {
+ // The embedded terminal owns keystrokes while it has focus: the Ghostty
+ // surface encodes the keydown and can write the pressed key into the shell
+ // before our window-level shortcut handling ever runs, regardless of any
+ // configured `when` clause on the jump command. Advertising jump hints
+ // here would promise a shortcut that instead types into the terminal, so
+ // never show them while the terminal is focused.
+ if (resolveContext(options).terminalFocus) {
+ return false;
+ }
+
const platform = resolvePlatform(options);
for (const command of THREAD_JUMP_KEYBINDING_COMMANDS) {