diff --git a/Frontend/assets/scripts/tools/scripts.js b/Frontend/assets/scripts/tools/scripts.js index 2b69577..124baa2 100644 --- a/Frontend/assets/scripts/tools/scripts.js +++ b/Frontend/assets/scripts/tools/scripts.js @@ -426,3 +426,41 @@ async function restRequest(port, endpoint, xmlData, transformData) { }); return result; } + + +function configurePastingInElement(elementId) { + const editorEle = document.getElementById(elementId); + + // Handle the `paste` event + editorEle.addEventListener('paste', function (e) { + // Prevent the default action + e.preventDefault(); + + // Get the copied text from the clipboard + const text = e.clipboardData + ? (e.originalEvent || e).clipboardData.getData('text/plain') + : // For IE + window.clipboardData + ? window.clipboardData.getData('Text') + : ''; + + if (document.queryCommandSupported('insertText')) { + document.execCommand('insertText', false, text); + } else { + // Insert text at the current position of caret + const range = document.getSelection().getRangeAt(0); + range.deleteContents(); + + const textNode = document.createTextNode(text); + range.insertNode(textNode); + range.selectNodeContents(textNode); + range.collapse(false); + + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + } + highlightSyntax(editorEle.id); + + }); +} \ No newline at end of file diff --git a/Frontend/tools/jsonFormatter.html b/Frontend/tools/jsonFormatter.html index a24b29a..e316c13 100644 --- a/Frontend/tools/jsonFormatter.html +++ b/Frontend/tools/jsonFormatter.html @@ -13,7 +13,7 @@ -
+