Skip to content

Commit 19e0fd2

Browse files
committed
fix(web): launcher shortcuts no longer hijack the empty composer
The right-panel empty-state launcher installed a capture-phase keydown handler that claimed its letters from a focused but empty chat composer, treating at-rest contenteditables as non-typing contexts. Typing a prompt that starts with t, b, f, d, p, or a would instead open that surface - for T, a live terminal that autofocuses and receives the rest of the prompt plus any Enter presses as shell input. Treat every contenteditable as a typing context regardless of content, matching the launcher's own documented contract of working only outside typing contexts. Letters still open surfaces when focus sits elsewhere. ox-alpha via opencode
1 parent be7d35a commit 19e0fd2

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎apps/web/src/components/RightPanelTabs.test.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type { DesktopPreviewFavicon, PreviewSessionSnapshot } from "@t3tools/con
22
import { renderToStaticMarkup } from "react-dom/server";
33
import { describe, expect, it } from "vite-plus/test";
44

5-
import { RightPanelTabs, surfaceShortcutActionForKey, tabMuteMenuItem } from "./RightPanelTabs";
5+
import {
6+
RightPanelTabs,
7+
surfaceShortcutActionForKey,
8+
surfaceShortcutTargetsTypingContext,
9+
tabMuteMenuItem,
10+
} from "./RightPanelTabs";
611

712
function shortcutEvent(
813
key: string,
@@ -166,6 +171,26 @@ describe("surface shortcuts", () => {
166171
});
167172
});
168173

174+
describe("surface shortcut typing contexts", () => {
175+
const targetIn = (selector: string | null) => ({
176+
closest: (selectors: string) => (selector === null ? null : { matches: selector }),
177+
});
178+
179+
it("treats form fields and every contenteditable as typing contexts", () => {
180+
expect(surfaceShortcutTargetsTypingContext(targetIn("input"))).toBe(true);
181+
expect(surfaceShortcutTargetsTypingContext(targetIn("textarea"))).toBe(true);
182+
expect(surfaceShortcutTargetsTypingContext(targetIn("select"))).toBe(true);
183+
// The chat composer is a contenteditable that sits empty until a draft
184+
// exists; launcher letters claimed from it redirected prompts into shells.
185+
expect(surfaceShortcutTargetsTypingContext(targetIn("[contenteditable]"))).toBe(true);
186+
});
187+
188+
it("claims letters when focus sits outside any editable", () => {
189+
expect(surfaceShortcutTargetsTypingContext(targetIn(null))).toBe(false);
190+
expect(surfaceShortcutTargetsTypingContext(null)).toBe(false);
191+
});
192+
});
193+
169194
describe("RightPanelTabs audio indicator", () => {
170195
// A muted tab only shows the indicator while it is actually making sound:
171196
// arming mute on a quiet tab is deliberate and stays invisible until there

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ export function surfaceShortcutActionForKey<
190190
);
191191
}
192192

193+
/**
194+
* A focused editable is a typing context whether or not it has text yet: an
195+
* empty chat composer at rest is still where the user's next keystrokes are
196+
* meant to land, and claiming launcher letters from it would redirect prompts
197+
* into whatever surface opens.
198+
*/
199+
export function surfaceShortcutTargetsTypingContext(
200+
target: { closest(selectors: string): unknown } | null,
201+
): boolean {
202+
return target?.closest("input, textarea, select, [contenteditable]") != null;
203+
}
204+
193205
function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
194206
return (
195207
<Tooltip>
@@ -329,13 +341,7 @@ function RightPanelEmptyState(props: {
329341
if (!action) return;
330342
if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
331343
const target = event.target;
332-
if (target instanceof HTMLElement) {
333-
if (target.closest("input, textarea, select")) return;
334-
// An empty contenteditable (the chat composer at rest) does not
335-
// count as typing; letters only become text once a draft exists.
336-
const editable = target.isContentEditable ? target : target.closest("[contenteditable]");
337-
if (editable && (editable.textContent ?? "").trim().length > 0) return;
338-
}
344+
if (target instanceof Element && surfaceShortcutTargetsTypingContext(target)) return;
339345
event.preventDefault();
340346
event.stopPropagation();
341347
action.onClick();

0 commit comments

Comments
 (0)