From 7c51f07858de8f75d0dd5efa7733bf65cb398c5b Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 9 May 2026 18:17:39 -0700 Subject: [PATCH] fix: allow any composer ancestor for cmd+enter submit (#1639) Co-authored-by: Orca --- .../src/lib/new-workspace-enter-guard.test.ts | 40 ++++++++----------- .../src/lib/new-workspace-enter-guard.ts | 9 +++-- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/renderer/src/lib/new-workspace-enter-guard.test.ts b/src/renderer/src/lib/new-workspace-enter-guard.test.ts index 8c9ee59af..e18f6321d 100644 --- a/src/renderer/src/lib/new-workspace-enter-guard.test.ts +++ b/src/renderer/src/lib/new-workspace-enter-guard.test.ts @@ -12,19 +12,18 @@ function makeEvent(overrides: Partial<{ isComposing: boolean; shiftKey: boolean } class FakeHTMLElement extends EventTarget { - private readonly children = new Set() + private readonly descendants = new Set() append(child: FakeHTMLElement): void { - this.children.add(child) + this.descendants.add(child) } contains(target: EventTarget): boolean { - return target === this || this.children.has(target as FakeHTMLElement) + return target === this || this.descendants.has(target as FakeHTMLElement) } } let previousHTMLElement: typeof globalThis.HTMLElement | undefined -let previousDocument: typeof globalThis.document | undefined describe('shouldSuppressEnterSubmit', () => { it('returns false for a plain Enter with no composition', () => { @@ -53,17 +52,10 @@ describe('shouldSuppressEnterSubmit', () => { describe('shouldAllowComposerEnterSubmitTarget', () => { beforeEach(() => { previousHTMLElement = globalThis.HTMLElement - previousDocument = globalThis.document - const body = new FakeHTMLElement() - const documentElement = new FakeHTMLElement() Object.defineProperty(globalThis, 'HTMLElement', { configurable: true, value: FakeHTMLElement }) - Object.defineProperty(globalThis, 'document', { - configurable: true, - value: { body, documentElement } - }) }) afterEach(() => { @@ -71,10 +63,6 @@ describe('shouldAllowComposerEnterSubmitTarget', () => { configurable: true, value: previousHTMLElement }) - Object.defineProperty(globalThis, 'document', { - configurable: true, - value: previousDocument - }) }) it('allows targets inside the composer', () => { @@ -87,21 +75,25 @@ describe('shouldAllowComposerEnterSubmitTarget', () => { ) }) - it('allows body/document targets after a source selection drops focus', () => { + it('allows ancestor targets after a source selection drops focus', () => { + // Why: post-selection focus can land on body, html, or the DialogContent + // root — any ancestor wrapping the composer is a legitimate fallback. const composer = new FakeHTMLElement() + const dialogContent = new FakeHTMLElement() + const body = new FakeHTMLElement() + dialogContent.append(composer) + body.append(composer) + body.append(dialogContent) expect( - shouldAllowComposerEnterSubmitTarget(document.body, composer as unknown as HTMLElement) - ).toBe(true) - expect( - shouldAllowComposerEnterSubmitTarget( - document.documentElement, - composer as unknown as HTMLElement - ) + shouldAllowComposerEnterSubmitTarget(dialogContent, composer as unknown as HTMLElement) ).toBe(true) + expect(shouldAllowComposerEnterSubmitTarget(body, composer as unknown as HTMLElement)).toBe( + true + ) }) - it('rejects targets outside the composer', () => { + it('rejects sibling targets outside the composer', () => { const composer = new FakeHTMLElement() const outside = new FakeHTMLElement() diff --git a/src/renderer/src/lib/new-workspace-enter-guard.ts b/src/renderer/src/lib/new-workspace-enter-guard.ts index fc016c062..0359a4892 100644 --- a/src/renderer/src/lib/new-workspace-enter-guard.ts +++ b/src/renderer/src/lib/new-workspace-enter-guard.ts @@ -28,8 +28,9 @@ export function shouldAllowComposerEnterSubmitTarget( if (composer?.contains(target)) { return true } - // Why: selecting a PR/issue/Linear row replaces the focused input with a - // source pill, and Chromium can retarget the next global keydown to body. - // Keep the modal shortcut alive for that post-selection focus fallback. - return target === document.body || target === document.documentElement + // Why: selecting a PR/issue/Linear row tears down the focused input and + // Radix's focus restore can land on body/documentElement, the DialogContent + // root, or any other ancestor wrapping the composer. Allow any ancestor so + // the modal's Cmd/Ctrl+Enter shortcut keeps firing post-selection. + return composer ? target.contains(composer) : false }