Updated paste custom logic.
This commit is contained in:
parent
8da0dba458
commit
0bb54a3662
1 changed files with 14 additions and 3 deletions
|
|
@ -188,18 +188,29 @@ export default {
|
|||
methods: {
|
||||
trimOnPaste(evt) {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
|
||||
const input = document.getElementById(evt.srcElement.id);
|
||||
const originalValue = input.value;
|
||||
const startPosition = input.selectionStart;
|
||||
const endPosition = input.selectionEnd;
|
||||
const selectionLength = endPosition - startPosition;
|
||||
|
||||
let data = null;
|
||||
if (evt.type === 'paste') {
|
||||
data = evt.clipboardData || window.clipboardData;
|
||||
} else {
|
||||
evt.preventDefault();
|
||||
data = evt.dataTransfer;
|
||||
}
|
||||
|
||||
const value = data.getData('Text')?.trim();
|
||||
const textValue = data.getData('Text');
|
||||
|
||||
this.$emit('update:modelValue', value);
|
||||
// Insert the pasted/dropped string at the index position
|
||||
const arrOriginalString = originalValue.split('');
|
||||
arrOriginalString.splice(startPosition, selectionLength, textValue);
|
||||
const blendedString = arrOriginalString.join('');
|
||||
|
||||
this.$emit('update:modelValue', blendedString);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue