Skip to content

The agent that grows with you

fix(desktop): keep the inline message edit open when a bubble is clicked

teknium1c450ed513378
diff --git a/apps/desktop/DESIGN.md b/apps/desktop/DESIGN.md
index 6fa6b8795ec..62f513adfe8 100644
--- a/apps/desktop/DESIGN.md
+++ b/apps/desktop/DESIGN.md
@@ -338,6 +338,9 @@ so glass and message-bubble transparency do not reveal scrolling text.
focus callbacks cannot replace that choice, and a live transcript selection
is never cleared by focus-follow. Movement within the same pane
must not flush React; deliberate Tab navigation and clicked controls still work.
+ An inline message edit is a typing target of its own: opening one keeps focus
+ in the edit editor, and neither its mount-time focus nor mouse movement while
+ it is open hands the caret back to the pane composer.
Active dictation or voice conversation pins the recipient until capture ends,
keeping the microphone's stop controls and shortcut attached to its owner.
- Status-stack rows use `StatusRow` with a leading `dismiss` action, a state
diff --git a/apps/desktop/src/app/chat/composer/floating-target.ts b/apps/desktop/src/app/chat/composer/floating-target.ts
index f28d8224411..43869924587 100644
--- a/apps/desktop/src/app/chat/composer/floating-target.ts
+++ b/apps/desktop/src/app/chat/composer/floating-target.ts
@@ -4,7 +4,7 @@ import { $activeTreeGroup, $hoveredTreeGroup, noteActiveTreeGroup } from '@/comp
import { $composerPopout } from '@/store/composer-popout'
import { $floatingComposerOwner, type FloatingComposerOwner } from './floating-state'
-import { focusComposerInput, markActiveComposer } from './focus'
+import { EDIT_COMPOSER_ROOT, focusComposerInput, markActiveComposer } from './focus'
import { placeCaretEnd } from './rich-editor'
const surfaces = new Map<string, Omit<FloatingComposerOwner, 'id'>>()
@@ -15,6 +15,13 @@ let pointerDownTarget: Element | null = null
let keyboardNavigation = false
let reconcileQueued = false
+/** The inline message edit lives in the transcript, outside every composer
+ * host, and takes focus programmatically when a bubble is clicked. That focus
+ * is the user's choice, not a delayed callback to redirect: stealing it hands
+ * the caret back to the pane composer, and the edit's blur guard then cancels
+ * the edit ~80ms after it opened (#112935). */
+const inInlineEdit = (el: Element | null) => Boolean(el?.closest(EDIT_COMPOSER_ROOT))
+
function rememberCaret(editor: EventTarget | null) {
const selection = window.getSelection()
@@ -153,7 +160,7 @@ function trackPointer(event: PointerEvent) {
active.dataset.slot === 'composer-rich-input' &&
active.closest<HTMLElement>('[data-composer-owner]')?.dataset.composerOwner === id
- if (event.type === 'pointermove' && !alreadyTyping) {
+ if (event.type === 'pointermove' && !alreadyTyping && !inInlineEdit(active)) {
focusSelectedComposer()
}
}
@@ -181,9 +188,10 @@ function trackFocus(event: FocusEvent) {
return
}
- // A delayed focus/restore isn't a navigation gesture. A clicked control or
- // keyboard Tab still keeps its normal focus, without redirecting to the input.
- if (keyboardNavigation || (pointerDownTarget && target.contains(pointerDownTarget))) {
+ // A delayed focus/restore isn't a navigation gesture. A clicked control,
+ // keyboard Tab, or the inline edit opened by a bubble click still keeps its
+ // normal focus, without redirecting to the input.
+ if (keyboardNavigation || inInlineEdit(target) || (pointerDownTarget && target.contains(pointerDownTarget))) {
flushSync(() => selectSurface(id))
} else {
// A refused redirect leaves focus where it landed: that element's focusin
diff --git a/apps/desktop/src/app/chat/composer/focus.ts b/apps/desktop/src/app/chat/composer/focus.ts
index 274fea5be34..b9d6caf8636 100644
--- a/apps/desktop/src/app/chat/composer/focus.ts
+++ b/apps/desktop/src/app/chat/composer/focus.ts
@@ -53,7 +53,7 @@ const VOICE_TOGGLE_EVENT = 'hermes:composer-voice-toggle'
const MODEL_MENU_EVENT = 'hermes:composer-model-menu'
/** Inline edit composer root — mounted only while a user bubble is being edited. */
-const EDIT_COMPOSER_ROOT = '[data-slot="aui_edit-composer-root"]'
+export const EDIT_COMPOSER_ROOT = '[data-slot="aui_edit-composer-root"]'
/** Attribute-safe selector fragment. jsdom (vitest) does not ship `CSS.escape`. */
const cssEscape = (value: string): string => {
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message-edit-shared-composer.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-message-edit-shared-composer.test.tsx
new file mode 100644
index 00000000000..bc0e05b5a3c
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/thread/user-message-edit-shared-composer.test.tsx
@@ -0,0 +1,131 @@
+// @vitest-environment jsdom
+// The inline edit composer opens inside a chat pane whose composer surface is
+// registered with the shared floating-composer recipient tracker
+// (`floating-target.ts`). That tracker redirects stray focus to the pane's
+// composer; the edit editor's mount-time focus and the user's mouse movement
+// while editing must not count as stray, or the pane composer steals the caret
+// and the edit's blur guard cancels the edit right after it opened (#112935).
+import { AssistantRuntimeProvider, ExportedMessageRepository, type ThreadMessage } from '@assistant-ui/react'
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { useState } from 'react'
+import { afterEach, beforeAll, describe, expect, it } from 'vitest'
+
+import { FloatingComposerSurface } from '@/app/chat/composer/floating-surface'
+import { ComposerScopeProvider, ComposerSurfaceProvider, MAIN_COMPOSER_SCOPE } from '@/app/chat/composer/scope'
+import { PaneGroupContext, PaneVisibleContext } from '@/components/pane-shell/pane-visibility'
+import { useIncrementalExternalStoreRuntime } from '@/lib/incremental-external-store-runtime'
+
+import { assistantMessage, stubThreadEnvironment, stubThreadViewportSize, userMessage } from '../test-utils'
+
+import { Thread } from '.'
+
+stubThreadEnvironment()
+stubThreadViewportSize()
+
+// jsdom does not make contenteditable focusable like Chromium does; give the
+// production editor a tab stop the moment production code tries to focus it.
+beforeAll(() => {
+ const nativeFocus = HTMLElement.prototype.focus
+
+ HTMLElement.prototype.focus = function focus(options?: FocusOptions) {
+ if (this.getAttribute('contenteditable') === 'true' && !this.hasAttribute('tabindex')) {
+ this.tabIndex = 0
+ }
+
+ nativeFocus.call(this, options)
+ }
+})
+
+afterEach(() => {
+ cleanup()
+})
+
+const noopAsync = async () => {}
+const EDIT_ROOT = '[data-slot="aui_edit-composer-root"]'
+
+// Mirrors chat/index.tsx: the transcript and the pane's composer share one
+// `[data-chat-surface]`, and the composer mounts through FloatingComposerSurface.
+function Harness() {
+ const [repository] = useState(() => ExportedMessageRepository.fromArray([userMessage(), assistantMessage()]))
+
+ const runtime = useIncrementalExternalStoreRuntime<ThreadMessage>({
+ messageRepository: repository,
+ isRunning: false,
+ setMessages: () => {},
+ onNew: noopAsync,
+ onEdit: noopAsync,
+ onCancel: noopAsync,
+ onReload: noopAsync
+ })
+
+ return (
+ <PaneGroupContext value="group-1">
+ <PaneVisibleContext value>
+ <ComposerScopeProvider value={{ ...MAIN_COMPOSER_SCOPE, target: 'main' }}>
+ <ComposerSurfaceProvider value="surface-1">
+ <div data-chat-surface="" data-composer-surface-id="surface-1" data-tree-group="group-1">
+ <AssistantRuntimeProvider runtime={runtime}>
+ <Thread cwd={null} gateway={null} sessionId="session-1" />
+ </AssistantRuntimeProvider>
+ <FloatingComposerSurface>
+ <div aria-label="Message" contentEditable data-slot="composer-rich-input" role="textbox" tabIndex={0} />
+ </FloatingComposerSurface>
+ </div>
+ </ComposerSurfaceProvider>
+ </ComposerScopeProvider>
+ </PaneVisibleContext>
+ </PaneGroupContext>
+ )
+}
+
+async function openEdit() {
+ const view = render(<Harness />)
+ const main = screen.getByRole('textbox', { name: 'Message' })
+ main.focus()
+
+ const bubble = await screen.findByRole('button', { name: 'Edit message' })
+
+ await act(async () => {
+ fireEvent.pointerDown(bubble, { button: 0 })
+ // The bubble click blurs the pane composer: on macOS a <button> never
+ // takes mouse focus; elsewhere it does and then unmounts with the bubble.
+ main.blur()
+ fireEvent.pointerUp(bubble, { button: 0 })
+ fireEvent.click(bubble)
+ })
+
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+
+ return { ...view, editor, main }
+}
+
+const settleBlurGuard = () =>
+ act(async () => {
+ await new Promise(resolve => window.setTimeout(resolve, 200))
+ })
+
+describe('inline edit inside a shared composer surface', () => {
+ it('keeps the edit composer open and focused after the bubble click', async () => {
+ const { container, editor } = await openEdit()
+
+ await settleBlurGuard()
+
+ expect(container.querySelector(EDIT_ROOT)).toBeTruthy()
+ expect(window.document.activeElement).toBe(editor)
+ })
+
+ it('does not hand the caret back to the pane composer when the mouse moves over the pane', async () => {
+ const { container, editor } = await openEdit()
+ const surface = container.querySelector<HTMLElement>('[data-chat-surface]')!
+
+ await act(async () => {
+ fireEvent.pointerMove(surface, { clientX: 120, clientY: 80 })
+ fireEvent.pointerMove(surface, { clientX: 140, clientY: 96 })
+ })
+
+ await settleBlurGuard()
+
+ expect(container.querySelector(EDIT_ROOT)).toBeTruthy()
+ expect(window.document.activeElement).toBe(editor)
+ })
+})