Skip to content

The agent that grows with you

fix(desktop): keep inline edit placeholders off entered text

brooklyn!2e320e6d1a81
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
index 9ae6f5fa433..460c464501e 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
@@ -36,8 +36,10 @@ import {
} from '@/app/chat/composer/inline-refs'
import { chipTypedPathOnSpace, pathifyRefs } from '@/app/chat/composer/path-refs'
import {
+ beginComposerComposition,
composerPlainText,
insertComposerContentsAtCaret,
+ markEditorEmptiness,
placeCaretEnd,
refChipElement,
renderComposerContents,
@@ -257,6 +259,9 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
const syncDraftFromEditor = useCallback(
(editor: HTMLDivElement) => {
+ // Native edits bypass renderComposerContents, so refresh the placeholder
+ // marker here as well, just like the main composer.
+ markEditorEmptiness(editor)
const nextDraft = sanitizeComposerInput(composerPlainText(editor))
if (nextDraft !== draftRef.current) {
@@ -854,8 +859,9 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
composingRef.current = false
flushEditorToDraft(event.currentTarget)
}}
- onCompositionStart={() => {
+ onCompositionStart={event => {
composingRef.current = true
+ beginComposerComposition(event.currentTarget)
}}
onDragOver={handleDragOver}
onDrop={handleDrop}
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
index 98449a0cb33..f7471002381 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
@@ -87,6 +87,53 @@ describe('click-to-edit user message', () => {
})
})
+ it('hides the placeholder when a cleared inline edit receives text again', async () => {
+ render(<IncrementalHarness onEdit={async () => {}} />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ // jsdom does not make contenteditable focusable like Chromium does.
+ editor.tabIndex = 0
+ editor.focus()
+ expect(document.activeElement).toBe(editor)
+
+ editor.replaceChildren()
+ fireEvent.input(editor)
+ await waitFor(() => expect(editor.hasAttribute('data-empty')).toBe(true))
+
+ editor.textContent = 'fade'
+ fireEvent.input(editor)
+ await waitFor(() => expect(editor.matches(':is(:empty, [data-empty])')).toBe(false))
+
+ editor.replaceChildren()
+ fireEvent.input(editor)
+ await waitFor(() => expect(editor.hasAttribute('data-empty')).toBe(true))
+ fireEvent.paste(editor, { clipboardData: { getData: () => 'pasted edit' } })
+ expect(editor.textContent).toBe('pasted edit')
+ expect(editor.matches(':is(:empty, [data-empty])')).toBe(false)
+ })
+
+ it('hides the inline edit placeholder during IME preedit and restores it on cancellation', async () => {
+ render(<IncrementalHarness onEdit={async () => {}} />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ editor.tabIndex = 0
+ editor.focus()
+
+ editor.replaceChildren()
+ fireEvent.input(editor)
+ await waitFor(() => expect(editor.hasAttribute('data-empty')).toBe(true))
+
+ fireEvent.compositionStart(editor)
+ editor.textContent = 'に'
+ fireEvent.input(editor)
+ expect(editor.matches(':is(:empty, [data-empty])')).toBe(false)
+
+ editor.replaceChildren()
+ fireEvent.compositionEnd(editor)
+ expect(editor.matches(':is(:empty, [data-empty])')).toBe(true)
+ })
+
it('does not submit an inline edit while IME composition is active', async () => {
const onEdit = vi.fn(async (_message: AppendMessage) => {})