Added syntax highlighting for XML Tools #156

Merged
bema merged 33 commits from bema/func/syntax_highlight into master 2023-05-08 11:11:18 +02:00
5 changed files with 44 additions and 16 deletions
Showing only changes of commit 2760ad4e0f - Show all commits

View File

@@ -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);
});
</script>
</body>

View File

@@ -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);
});
</script>
</body>

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});
</script>