From 0c0cfd2d22c228f7a3a130eab2bb7a53b821e24a Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 8 Apr 2026 19:02:06 +0100 Subject: [PATCH] fix(ui): keep speech input chained and scrolled to bottom --- .../components/prompt-input/usePromptVoiceInput.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/components/prompt-input/usePromptVoiceInput.ts b/packages/ui/src/components/prompt-input/usePromptVoiceInput.ts index 0b8f93f8..6bcc8746 100644 --- a/packages/ui/src/components/prompt-input/usePromptVoiceInput.ts +++ b/packages/ui/src/components/prompt-input/usePromptVoiceInput.ts @@ -169,18 +169,25 @@ export function usePromptVoiceInput(options: UsePromptVoiceInputOptions) { const textarea = options.getTextarea() const start = textarea ? textarea.selectionStart : current.length const end = textarea ? textarea.selectionEnd : current.length + const wasCursorAtEnd = end === current.length + const wasScrolledToBottom = textarea + ? textarea.scrollHeight - (textarea.scrollTop + textarea.clientHeight) <= 4 + : false const before = current.slice(0, start) const after = current.slice(end) - const prefix = before.length > 0 && !/\s$/.test(before) ? " " : "" - const suffix = after.length > 0 && !/^\s/.test(after) ? " " : "" + const prefix = "" + const suffix = after.length > 0 && !after.startsWith("\n") ? "\n" : "" const nextValue = `${before}${prefix}${text}${suffix}${after}` - const cursor = before.length + prefix.length + text.length + const cursor = before.length + prefix.length + text.length + suffix.length options.setPrompt(nextValue) if (textarea) { setTimeout(() => { textarea.focus() textarea.setSelectionRange(cursor, cursor) + if (wasCursorAtEnd || wasScrolledToBottom) { + textarea.scrollTop = textarea.scrollHeight + } }, 0) } }