copy and paste 버그 수정
This commit is contained in:
@@ -44,6 +44,39 @@ class EditableInputView {
|
|||||||
this.controller.additionalCallback(this.model.getValue());
|
this.controller.additionalCallback(this.model.getValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.editableDiv.addEventListener('paste', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (navigator.clipboard && navigator.clipboard.readText) {
|
||||||
|
navigator.clipboard.readText().then(text => {
|
||||||
|
this.insertTextAtCursor(text);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('Failed to read clipboard contents: ', err);
|
||||||
|
// Fallback to using clipboardData from the paste event
|
||||||
|
const text = (event.clipboardData || window.clipboardData).getData('text');
|
||||||
|
this.insertTextAtCursor(text);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const text = (event.clipboardData || window.clipboardData).getData('text');
|
||||||
|
this.insertTextAtCursor(text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
insertTextAtCursor(text) {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
if (!selection.rangeCount) return;
|
||||||
|
|
||||||
|
const range = selection.getRangeAt(0);
|
||||||
|
range.deleteContents();
|
||||||
|
const textNode = document.createTextNode(text);
|
||||||
|
range.insertNode(textNode);
|
||||||
|
|
||||||
|
range.setStartAfter(textNode);
|
||||||
|
range.setEndAfter(textNode);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
|
||||||
|
this.controller.handleInput(this.editableDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUI() {
|
updateUI() {
|
||||||
|
|||||||
Reference in New Issue
Block a user