diff --git a/ApiTestManager/src/components/EditableInput.js b/ApiTestManager/src/components/EditableInput.js index 04487e9..fafaa53 100644 --- a/ApiTestManager/src/components/EditableInput.js +++ b/ApiTestManager/src/components/EditableInput.js @@ -44,6 +44,39 @@ class EditableInputView { 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() {