Syntax highlighting works fully for XPath

This commit is contained in:
2023-04-25 14:52:06 +02:00
parent 1ba2d328e9
commit c3774c2629
2 changed files with 63 additions and 17 deletions

View File

@@ -68,7 +68,7 @@
<!-- <textarea disabled id="resultArea" name="resultArea"
class="textarea-300 bordered-field vertically-resizeable max-width" style="margin-bottom: 50px;"
rows="10" cols="100"></textarea> -->
<pre><code class="language-xml bordered-field textarea-300" id="resultArea" contenteditable="True"></code></pre>
<pre><code class="language-xml bordered-field textarea-300" id="resultArea" "></code></pre>
</div>
</div>
@@ -17266,6 +17266,43 @@
})
}
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);
highlightSyntax(editorEle.id);
} 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);
}
});
</script>
</body>