Skip to content

The agent that grows with you

fix(desktop): keep empty composer from collapsing

Denis354abd7c578d
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
index e92afa82f2f..cbb3417f5a7 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
@@ -255,7 +255,8 @@ export function useComposerDraft({
draftRef.current = ''
if (editorRef.current) {
- editorRef.current.replaceChildren()
+ renderComposerContents(editorRef.current, '')
+ placeCaretEnd(editorRef.current)
}
}, [setComposerText])
diff --git a/apps/desktop/src/app/chat/composer/inline-refs.ts b/apps/desktop/src/app/chat/composer/inline-refs.ts
index 5e282f6a040..618ce69b3f6 100644
--- a/apps/desktop/src/app/chat/composer/inline-refs.ts
+++ b/apps/desktop/src/app/chat/composer/inline-refs.ts
@@ -136,17 +136,22 @@ function buildRefFragment(
export function insertInlineRefsIntoEditor(editor: HTMLDivElement, refs: readonly InlineRefInput[]) {
const parsed = refs.map(parseInlineRef).filter((ref): ref is NonNullable<typeof ref> => ref !== null)
+ const hasEmptySentinel = editor.childNodes.length === 1 && editor.firstChild?.nodeName === 'BR'
if (!parsed.length) {
return null
}
+ if (hasEmptySentinel) {
+ editor.replaceChildren()
+ }
+
editor.focus({ preventScroll: true })
const selection = window.getSelection()
const range =
- selection?.rangeCount && editor.contains(selection.getRangeAt(0).commonAncestorContainer)
+ !hasEmptySentinel && selection?.rangeCount && editor.contains(selection.getRangeAt(0).commonAncestorContainer)
? selection.getRangeAt(0)
: null