From a9500276c808fa9c171b522434857ed8646271e1 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Tue, 2 Dec 2025 22:59:36 +0000 Subject: [PATCH] add expand control for pasted text attachments --- packages/ui/src/components/prompt-input.tsx | 71 ++++++++++++++++++- .../ui/src/styles/messaging/prompt-input.css | 6 +- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/prompt-input.tsx b/packages/ui/src/components/prompt-input.tsx index 0874c48c..461e3143 100644 --- a/packages/ui/src/components/prompt-input.tsx +++ b/packages/ui/src/components/prompt-input.tsx @@ -163,6 +163,53 @@ export default function PromptInput(props: PromptInputProps) { } } + function handleExpandTextAttachment(attachment: Attachment) { + if (attachment.source.type !== "text") return + + const textarea = textareaRef + const value = attachment.source.value + const match = attachment.display.match(/pasted #(\d+)/) + const placeholder = match ? `[pasted #${match[1]}]` : null + const currentText = prompt() + + let nextText = currentText + let selectionTarget: number | null = null + + if (placeholder) { + const placeholderIndex = currentText.indexOf(placeholder) + if (placeholderIndex !== -1) { + nextText = + currentText.substring(0, placeholderIndex) + + value + + currentText.substring(placeholderIndex + placeholder.length) + selectionTarget = placeholderIndex + value.length + } + } + + if (nextText === currentText) { + if (textarea) { + const start = textarea.selectionStart + const end = textarea.selectionEnd + nextText = currentText.substring(0, start) + value + currentText.substring(end) + selectionTarget = start + value.length + } else { + nextText = currentText + value + } + } + + setPrompt(nextText) + removeAttachment(props.instanceId, props.sessionId, attachment.id) + + if (textarea) { + setTimeout(() => { + textarea.focus() + if (selectionTarget !== null) { + textarea.setSelectionRange(selectionTarget, selectionTarget) + } + }, 0) + } + } + async function handlePaste(e: ClipboardEvent) { const items = e.clipboardData?.items if (!items) return @@ -813,13 +860,18 @@ export default function PromptInput(props: PromptInputProps) { {(attachment) => { const isImage = attachment.mediaType.startsWith("image/") + const textValue = attachment.source.type === "text" ? attachment.source.value : undefined + const isTextAttachment = typeof textValue === "string" return ( -
+
{attachment.filename} - {attachment.source.type === "text" ? attachment.display : attachment.filename} + {isTextAttachment ? attachment.display : attachment.filename} + + +