Просмотр исходного кода

Fixes #3862 - Text Modules cannot be undone using CRTL + Z

Mantas Masalskis 1 год назад
Родитель
Сommit
9ee5527357
1 измененных файлов с 19 добавлено и 0 удалено
  1. 19 0
      app/assets/javascripts/app/lib/base/jquery.textmodule.js

+ 19 - 0
app/assets/javascripts/app/lib/base/jquery.textmodule.js

@@ -367,6 +367,25 @@
           range.surroundContents(nnode)
           nnode.innerHTML = string
     }
+    else if (document.queryCommandSupported && document.queryCommandSupported('insertHTML')) {
+      if(!!window.chrome) { // Is Chrome-like browser? It will eat up the single trailing space!
+        range = document.getSelection().getRangeAt(0)
+
+        var walker         = document.createTreeWalker(document.body, NodeFilter.SHOW_ALL);
+        walker.currentNode = range.startContainer;
+        var previousNode   = walker.previousNode()
+
+        if(previousNode && !range.startContainer.previousSibling && ['<p></p>', '<div></div>'].includes(previousNode.outerHTML)) {
+          document.execCommand('insertHTML', false, "<br><br>")
+        }
+
+        if(range && range.endContainer.textContent && range.endContainer.textContent.match(/(?<=\S) $/)) {
+          document.execCommand('insertHTML', false, '&nbsp;')
+        }
+      }
+
+      document.execCommand('insertHTML', false, string)
+    }
     else {
       var sel = rangy.getSelection();
       if (!sel.rangeCount) return