From 26cc1fe682fa4ff1369b71a4a3666e4fa4a29989 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Fri, 4 Oct 2024 12:26:12 -0700 Subject: [PATCH] pasting text bug fix --- .../ChatContainer/PromptInput/index.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx index cc5ae14915..a14b70ac8d 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx @@ -122,9 +122,22 @@ export default function PromptInput({ const pasteText = e.clipboardData.getData("text/plain"); if (pasteText) { - const newPromptInput = promptInput + pasteText.trim(); + const textarea = textareaRef.current; + const start = textarea.selectionStart; + const end = textarea.selectionEnd; + const newPromptInput = + promptInput.substring(0, start) + + pasteText + + promptInput.substring(end); setPromptInput(newPromptInput); onChange({ target: { value: newPromptInput } }); + + // Set the cursor position after the pasted text + // we need to use setTimeout to prevent the cursor from being set to the end of the text + setTimeout(() => { + textarea.selectionStart = textarea.selectionEnd = + start + pasteText.length; + }, 0); } return; };