Skip to content

Commit ce7e614

Browse files
committed
fix(web): see past contenteditable=false islands when guarding launcher keys
Macroscope review: the nearest-match-then-check-attribute shape misclassified genuinely editable regions nested inside a contenteditable="false" island inside the composer, re-opening the keystroke hijacking this PR fixes. Adopt the repo's existing typing guard idiom from ComposerPendingUserInputPanel: [contenteditable]:not([contenteditable="false"]) lets closest reach the editable host around non-editable islands while standalone false islands stay shortcut-reachable. ox-alpha via opencode
1 parent c0aae95 commit ce7e614

2 files changed

Lines changed: 16 additions & 23 deletions

File tree

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

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

174174
describe("surface shortcut typing contexts", () => {
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) => ({
175+
// Selector-aware stub: closest() answers only tokens the combined selector
176+
// would actually match, mirroring how the browser resolves it.
177+
const makeTarget = (matches: string | null) => ({
178178
closest(selectors: string) {
179179
if (matches === null || !selectors.includes(matches)) return null;
180-
return {
181-
getAttribute: (name: string) =>
182-
name === "contenteditable" ? (contenteditableValue ?? null) : null,
183-
};
180+
return {};
184181
},
185182
});
186183

@@ -190,18 +187,14 @@ describe("surface shortcut typing contexts", () => {
190187
expect(surfaceShortcutTargetsTypingContext(makeTarget("select"))).toBe(true);
191188
// The chat composer is a contenteditable that sits empty until a draft
192189
// exists; launcher letters claimed from it redirected prompts into shells.
193-
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]", "true"))).toBe(true);
194-
// An empty attribute value still means editable.
195-
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]", ""))).toBe(true);
190+
// The :not clause sees past contenteditable="false" islands to an editable
191+
// host around them, so nested editors stay protected too.
192+
expect(surfaceShortcutTargetsTypingContext(makeTarget("[contenteditable]"))).toBe(true);
196193
});
197194

198-
it("ignores non-editable regions and bare focus targets", () => {
195+
it("claims letters when focus sits outside any editable region", () => {
199196
expect(surfaceShortcutTargetsTypingContext(null)).toBe(false);
200197
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-
);
205198
});
206199
});
207200

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +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. Non-editable islands marked
198-
* `contenteditable="false"` (chips inside the composer, standalone widgets)
199-
* stay shortcut-reachable.
197+
* into whatever surface opens. The `:not` clause lets `closest` see past
198+
* non-editable islands (`contenteditable="false"`) to an editable host around
199+
* them, matching ComposerPendingUserInputPanel's typing guard.
200200
*/
201201
export function surfaceShortcutTargetsTypingContext(
202-
target: {
203-
closest(selectors: string): { getAttribute(qualifiedName: string): string | null } | null;
204-
} | null,
202+
target: { closest(selectors: string): unknown } | null,
205203
): boolean {
206-
const editable = target?.closest("input, textarea, select, [contenteditable]") ?? null;
207-
return editable != null && editable.getAttribute("contenteditable") !== "false";
204+
return (
205+
target?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') !=
206+
null
207+
);
208208
}
209209

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

0 commit comments

Comments
 (0)