`caret.end()` sometimes added a new `<p>`
authorAlexander Ebert <ebert@woltlab.com>
Sun, 18 Sep 2016 20:28:52 +0000 (22:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 18 Sep 2016 20:33:14 +0000 (22:33 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 0a6c98a33313d8aee9efdf656801e35eb8b6d2b8..98af8cefacc63ebab01a867cd2caf11446d91919 100644 (file)
@@ -14,6 +14,25 @@ $.Redactor.prototype.WoltLabCaret = function() {
                                mpAfter.call(this, node);
                        }).bind(this);
                        
+                       var mpEnd = this.caret.end;
+                       this.caret.end = (function (node) {
+                               node = this.caret.prepare(node);
+                               
+                               if (node.nodeType === Node.ELEMENT_NODE && node.lastChild && node.lastChild.nodeName === 'P') {
+                                       var selection = window.getSelection();
+                                       var range = document.createRange();
+                                       range.selectNodeContents(node.lastChild);
+                                       range.collapse(false);
+                                       
+                                       selection.removeAllRanges();
+                                       selection.addRange(range);
+                                       
+                                       return;
+                               }
+                               
+                               return mpEnd.call(this, node);
+                       }).bind(this);
+                       
                        this.$editor[0].addEventListener(WCF_CLICK_EVENT, this.WoltLabCaret._handleEditorClick.bind(this));
                        
                        this.WoltLabCaret._initInternalRange();