mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-05-02 17:07:13 +00:00
Pasting text bug fix (#2425)
pasting text bug fix Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
cb4b0a878e
commit
52f2f87179
1 changed files with 14 additions and 1 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue