From 74f29035faa2d1121781d27bcc7286b7f15abe94 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Wed, 26 Apr 2023 11:43:44 +0200 Subject: [PATCH] Fixes and refactors --- Frontend/tools/jsonFormatter.html | 2 ++ Frontend/tools/xmlFormatter.html | 36 +++++++++++++++++++++++++++++++ Frontend/tools/xpath.html | 4 +--- Frontend/tools/xsd.html | 8 +++---- Frontend/tools/xslt.html | 10 ++------- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Frontend/tools/jsonFormatter.html b/Frontend/tools/jsonFormatter.html index 9bb8db9..a24b29a 100644 --- a/Frontend/tools/jsonFormatter.html +++ b/Frontend/tools/jsonFormatter.html @@ -241,6 +241,7 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); + } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -255,6 +256,7 @@ selection.removeAllRanges(); selection.addRange(range); } + highlightSyntax(editorEle.id); }); diff --git a/Frontend/tools/xmlFormatter.html b/Frontend/tools/xmlFormatter.html index 466d5ea..9a2331a 100644 --- a/Frontend/tools/xmlFormatter.html +++ b/Frontend/tools/xmlFormatter.html @@ -74,6 +74,42 @@ function init() { setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here'); } + + const editorEle = document.getElementById('xmlArea'); + + // 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); + + }); diff --git a/Frontend/tools/xpath.html b/Frontend/tools/xpath.html index f24a0ac..742d4f8 100644 --- a/Frontend/tools/xpath.html +++ b/Frontend/tools/xpath.html @@ -17274,7 +17274,6 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); - highlightSyntax(editorEle.id); } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -17288,9 +17287,8 @@ const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); - - } + highlightSyntax(editorEle.id); }); diff --git a/Frontend/tools/xsd.html b/Frontend/tools/xsd.html index d206018..ffe5274 100644 --- a/Frontend/tools/xsd.html +++ b/Frontend/tools/xsd.html @@ -129,7 +129,6 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); - highlightSyntax(editorEle.id); } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -144,8 +143,8 @@ selection.removeAllRanges(); selection.addRange(range); - } + highlightSyntax(editorEle.id); }); @@ -166,7 +165,7 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); - highlightSyntax(transformEle.id); + } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -180,9 +179,8 @@ const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); - - } + highlightSyntax(transformEle.id); }); diff --git a/Frontend/tools/xslt.html b/Frontend/tools/xslt.html index 69782f3..2407332 100644 --- a/Frontend/tools/xslt.html +++ b/Frontend/tools/xslt.html @@ -1243,7 +1243,6 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); - highlightSyntax(editorEle.id); } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -1257,10 +1256,8 @@ const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); - - } - + highlightSyntax(editorEle.id); }); const transformEle = document.getElementById('transformArea'); @@ -1280,7 +1277,6 @@ if (document.queryCommandSupported('insertText')) { document.execCommand('insertText', false, text); - highlightSyntax(transformEle.id); } else { // Insert text at the current position of caret const range = document.getSelection().getRangeAt(0); @@ -1294,10 +1290,8 @@ const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); - - } - + highlightSyntax(transformEle.id); });