Skip to content
Snippets Groups Projects
Unverified Commit 52f2f871 authored by Sean Hatfield's avatar Sean Hatfield Committed by GitHub
Browse files

Pasting text bug fix (#2425)


pasting text bug fix

Co-authored-by: default avatarTimothy Carambat <rambat1010@gmail.com>
parent cb4b0a87
No related branches found
No related tags found
No related merge requests found
......@@ -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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment