Skip to content

Commit

Permalink
Pasting text bug fix (#2425)
Browse files Browse the repository at this point in the history
pasting text bug fix

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
  • Loading branch information
shatfield4 and timothycarambat authored Oct 15, 2024
1 parent cb4b0a8 commit 52f2f87
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 52f2f87

Please sign in to comment.