mirror of
https://github.com/n8n-io/n8n.git
synced 2025-11-20 17:46:34 +00:00
fix: trim text when pasting in chat
This commit is contained in:
parent
c434d58932
commit
e9effd3b7e
@ -118,6 +118,33 @@ function handleKeydownTextarea(e: KeyboardEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
function handlePaste(e: ClipboardEvent) {
|
||||
e.preventDefault();
|
||||
|
||||
const text = e.clipboardData?.getData('text');
|
||||
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Text copied from conversation history tends to
|
||||
// include unnecessary leading & trailing whitespaces, so we're removing them
|
||||
const trimmed = text.trim();
|
||||
|
||||
const textarea = e.target as HTMLTextAreaElement;
|
||||
const start = textarea.selectionStart;
|
||||
const end = textarea.selectionEnd;
|
||||
const before = message.value.substring(0, start);
|
||||
const after = message.value.substring(end);
|
||||
|
||||
message.value = before + trimmed + after;
|
||||
|
||||
setTimeout(() => {
|
||||
const newPosition = start + trimmed.length;
|
||||
textarea.setSelectionRange(newPosition, newPosition);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function handleClickInputWrapper() {
|
||||
inputRef.value?.focus();
|
||||
}
|
||||
@ -225,6 +252,7 @@ defineExpose({
|
||||
autofocus
|
||||
:disabled="isMissingCredentials || !selectedModel"
|
||||
@keydown="handleKeydownTextarea"
|
||||
@paste="handlePaste"
|
||||
/>
|
||||
|
||||
<div :class="$style.footer">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user