Handle CRLF newlines properly when pasting
This commit is contained in:
parent
718af6f7fa
commit
99d26c44e0
|
@ -758,7 +758,7 @@ function chunkOnTextInput(event) {
|
||||||
// mobile devices, but the other method is also here as
|
// mobile devices, but the other method is also here as
|
||||||
// a fallback
|
// a fallback
|
||||||
if(document.queryCommandSupported && document.execCommand && document.queryCommandSupported('insertHTML')) {
|
if(document.queryCommandSupported && document.execCommand && document.queryCommandSupported('insertHTML')) {
|
||||||
document.execCommand('insertHTML', false, event.originalEvent.data.slice(0, -1).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\n/g, '<br/>') + '<br id="_EDITOR_LINEBREAK_"/><span id="_EDITOR_SENTINEL_">|</span>');
|
document.execCommand('insertHTML', false, event.originalEvent.data.slice(0, -1).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/(?=\r|\n)\r?\n?/g, '<br/>') + '<br id="_EDITOR_LINEBREAK_"/><span id="_EDITOR_SENTINEL_">|</span>');
|
||||||
var t = $('#_EDITOR_SENTINEL_').contents().filter(function() { return this.nodeType === 3; })[0];
|
var t = $('#_EDITOR_SENTINEL_').contents().filter(function() { return this.nodeType === 3; })[0];
|
||||||
} else {
|
} else {
|
||||||
var t = document.createTextNode('|');
|
var t = document.createTextNode('|');
|
||||||
|
@ -1043,13 +1043,13 @@ function chunkOnPaste(event) {
|
||||||
// paste as plaintext
|
// paste as plaintext
|
||||||
if(event.originalEvent.clipboardData && document.queryCommandSupported && document.execCommand && document.queryCommandSupported('insertText')) {
|
if(event.originalEvent.clipboardData && document.queryCommandSupported && document.execCommand && document.queryCommandSupported('insertText')) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.execCommand('insertHTML', false, event.originalEvent.clipboardData.getData('text/plain').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\n/g, '<br/>'));
|
document.execCommand('insertHTML', false, event.originalEvent.clipboardData.getData('text/plain').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/(?=\r|\n)\r?\n?/g, '<br/>'));
|
||||||
} else if (event.originalEvent.clipboardData) {
|
} else if (event.originalEvent.clipboardData) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var s = getSelection(); // WARNING: Do not use rangy.getSelection() instead of getSelection()
|
var s = getSelection(); // WARNING: Do not use rangy.getSelection() instead of getSelection()
|
||||||
var r = s.getRangeAt(0);
|
var r = s.getRangeAt(0);
|
||||||
r.deleteContents();
|
r.deleteContents();
|
||||||
var nodes = Array.from($('<span>' + event.originalEvent.clipboardData.getData('text/plain').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\n/g, '<br/>') + '</span>')[0].childNodes);
|
var nodes = Array.from($('<span>' + event.originalEvent.clipboardData.getData('text/plain').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/(?=\r|\n)\r?\n?/g, '<br/>') + '</span>')[0].childNodes);
|
||||||
for(var i = 0; i < nodes.length; i++) {
|
for(var i = 0; i < nodes.length; i++) {
|
||||||
r.insertNode(nodes[i]);
|
r.insertNode(nodes[i]);
|
||||||
r.collapse(false);
|
r.collapse(false);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script src="static/jquery-3.6.0.min.js"></script>
|
<script src="static/jquery-3.6.0.min.js"></script>
|
||||||
<script src="static/socket.io.min.js"></script>
|
<script src="static/socket.io.min.js"></script>
|
||||||
<script src="static/application.js?ver=1.16.2h"></script>
|
<script src="static/application.js?ver=1.16.2i"></script>
|
||||||
<script src="static/bootstrap.min.js"></script>
|
<script src="static/bootstrap.min.js"></script>
|
||||||
<script src="static/bootstrap-toggle.min.js"></script>
|
<script src="static/bootstrap-toggle.min.js"></script>
|
||||||
<script src="static/rangy-core.min.js"></script>
|
<script src="static/rangy-core.min.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue