paste 버그 수정

This commit is contained in:
현성필
2024-05-20 10:19:23 +09:00
parent 6a2c2d1ab3
commit 2c7d6ab2ce
+31 -7
View File
@@ -54,20 +54,44 @@ 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);
// }
// });
this.editableDiv.addEventListener('paste', (event) => { this.editableDiv.addEventListener('paste', (event) => {
event.preventDefault(); event.preventDefault();
if (navigator.clipboard && navigator.clipboard.readText) { let text = (event.clipboardData || window.clipboardData).getData('text/plain'); // Using 'text/plain' for compatibility
if (text) {
console.log('Pasted text:', text); // Debug: Log pasted text
this.insertTextAtCursor(text);
if (this.controller.additionalCallback) {
this.controller.additionalCallback(this.model.getValue());
}
} else if (navigator.clipboard && navigator.clipboard.readText) {
navigator.clipboard.readText().then(text => { navigator.clipboard.readText().then(text => {
console.log('Pasted text from clipboard API:', text); // Debug: Log pasted text
this.insertTextAtCursor(text); this.insertTextAtCursor(text);
if (this.controller.additionalCallback) {
this.controller.additionalCallback(this.model.getValue());
}
}).catch(err => { }).catch(err => {
console.error('Failed to read clipboard contents: ', 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 { } else {
const text = (event.clipboardData || window.clipboardData).getData('text'); console.error('No text found to paste and clipboard API not available.');
this.insertTextAtCursor(text);
} }
}); });
} }