From 00fc462c8fa2dbb797a8dcae284b72b14be93b69 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Fri, 24 Oct 2025 01:21:57 +0100 Subject: [PATCH] Add placeholder text for long paste attachments in prompt - Insert [pasted #N] at cursor position when pasting - Remove placeholder when attachment chip is deleted - Maintains cursor position after paste - User can see where paste was inserted in text flow --- src/components/prompt-input.tsx | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/components/prompt-input.tsx b/src/components/prompt-input.tsx index 00cf165b..85458c1e 100644 --- a/src/components/prompt-input.tsx +++ b/src/components/prompt-input.tsx @@ -40,14 +40,26 @@ export default function PromptInput(props: PromptInputProps) { const attachments = () => getAttachments(props.instanceId, props.sessionId) function handleRemoveAttachment(attachmentId: string) { - removeAttachment(props.instanceId, props.sessionId, attachmentId) - const currentAttachments = attachments() const attachment = currentAttachments.find((a) => a.id === attachmentId) - if (attachment && attachment.source.type === "file") { - const filename = attachment.filename + + removeAttachment(props.instanceId, props.sessionId, attachmentId) + + if (attachment) { const currentPrompt = prompt() - const newPrompt = currentPrompt.replace(`@${filename}`, "").replace(/\s+/g, " ").trim() + let newPrompt = currentPrompt + + if (attachment.source.type === "file") { + const filename = attachment.filename + newPrompt = currentPrompt.replace(`@${filename}`, "").replace(/\s+/g, " ").trim() + } else if (attachment.source.type === "text") { + const placeholderMatch = attachment.display.match(/pasted #(\d+)/) + if (placeholderMatch) { + const placeholder = `[pasted #${placeholderMatch[1]}]` + newPrompt = currentPrompt.replace(placeholder, "").replace(/\s+/g, " ").trim() + } + } + setPrompt(newPrompt) if (textareaRef) { @@ -78,6 +90,24 @@ export default function PromptInput(props: PromptInputProps) { const attachment = createTextAttachment(pastedText, display, filename) addAttachment(props.instanceId, props.sessionId, attachment) + + const textarea = textareaRef + if (textarea) { + const start = textarea.selectionStart + const end = textarea.selectionEnd + const currentText = prompt() + const placeholder = `[pasted #${count}]` + const newText = currentText.substring(0, start) + placeholder + currentText.substring(end) + setPrompt(newText) + + setTimeout(() => { + const newCursorPos = start + placeholder.length + textarea.setSelectionRange(newCursorPos, newCursorPos) + textarea.style.height = "auto" + textarea.style.height = Math.min(textarea.scrollHeight, 200) + "px" + textarea.focus() + }, 0) + } } }