Skip to content

Commit c0aae95

Browse files
committed
fix(web): keep launcher letters working on contenteditable=false islands
CodeRabbit review: the [contenteditable] attribute selector also matches contenteditable="false" elements, so chips inside the composer or standalone non-editable widgets would have been treated as typing contexts and lost launcher access. Inspect the nearest editable ancestor's attribute value instead of mere presence, and make the test stub selector-aware so it actually exercises the selector list. ox-alpha via opencode
1 parent 19e0fd2 commit c0aae95

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,36 @@ describe("surface shortcuts", () => {
172172
});
173173

174174
describe("surface shortcut typing contexts", () => {
175-
const targetIn = (selector: string | null) => ({
176-
closest: (selectors: string) => (selector === null ? null : { matches: selector }),
175+
// Selector-aware stub: closest() only answers when the requested selector
176+
// list contains the matched element, like a real DOM would.
177+
const makeTarget = (matches: string | null, contenteditableValue?: string | null) => ({
178+
closest(selectors: string) {
179+
if (matches === null || !selectors.includes(matches)) return null;
180+
return {
181+
getAttribute: (name: string) =>
182+
name === "contenteditable" ? (contenteditableValue ?? null) : null,
183+
};
184+
},
177185
});
178186

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);
187+
it("treats form fields and every editable region as typing contexts", () => {
188+
expect(surfaceShortcutTargetsTypingContext(makeTarget("input"))).toBe(true);
189+
expect(surfaceShortcutTargetsTypingContext(makeTarget("textarea"))).toBe(true);
190+
expect(surfaceShortcutTargetsTypingContext(makeTarget("select"))).toBe(true);
183191
// The chat composer is a contenteditable that sits empty until a draft
184192
// exists; launcher letters claimed from it redirected prompts into shells.
185-
expect(surfaceShortcutTargetsTypingContext(targetIn("[contenteditable]"))).toBe(true);
193+
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]", "true"))).toBe(true);
194+
// An empty attribute value still means editable.
195+
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]", ""))).toBe(true);
186196
});
187197

188-
it("claims letters when focus sits outside any editable", () => {
189-
expect(surfaceShortcutTargetsTypingContext(targetIn(null))).toBe(false);
198+
it("ignores non-editable regions and bare focus targets", () => {
190199
expect(surfaceShortcutTargetsTypingContext(null)).toBe(false);
200+
expect(surfaceShortcutTargetsTypingContext(makeTarget(null))).toBe(false);
201+
// Non-editable islands inside an editable host stay shortcut-reachable.
202+
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]", "false"))).toBe(
203+
false,
204+
);
191205
});
192206
});
193207

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,17 @@ export function surfaceShortcutActionForKey<
194194
* A focused editable is a typing context whether or not it has text yet: an
195195
* empty chat composer at rest is still where the user's next keystrokes are
196196
* meant to land, and claiming launcher letters from it would redirect prompts
197-
* into whatever surface opens.
197+
* into whatever surface opens. Non-editable islands marked
198+
* `contenteditable="false"` (chips inside the composer, standalone widgets)
199+
* stay shortcut-reachable.
198200
*/
199201
export function surfaceShortcutTargetsTypingContext(
200-
target: { closest(selectors: string): unknown } | null,
202+
target: {
203+
closest(selectors: string): { getAttribute(qualifiedName: string): string | null } | null;
204+
} | null,
201205
): boolean {
202-
return target?.closest("input, textarea, select, [contenteditable]") != null;
206+
const editable = target?.closest("input, textarea, select, [contenteditable]") ?? null;
207+
return editable != null && editable.getAttribute("contenteditable") !== "false";
203208
}
204209

205210
function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {

0 commit comments

Comments
 (0)