Fixed incorrect removal of newlines on quote insert
authorAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jun 2015 12:36:21 +0000 (14:36 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jun 2015 12:36:21 +0000 (14:36 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index 8ad7b8ef201ea9fe0cc4b957bdf06dddb41df574..63e9cfabf4b20c7395276a9c81a588d6f10d1ac3 100644 (file)
@@ -2148,7 +2148,12 @@ RedactorPlugins.wbbcode = function() {
                                
                                if ($current && $current.parentNode === this.$editor[0]) {
                                        if ($current.innerHTML.length) {
-                                               this.wutil.setCaretAfter($current);
+                                               if ($current.innerHTML === '\u200b') {
+                                                       this.caret.setEnd($current);
+                                               }
+                                               else {
+                                                       this.wutil.setCaretAfter($current);
+                                               }
                                        }
                                }
                                
@@ -2174,6 +2179,15 @@ RedactorPlugins.wbbcode = function() {
                                        
                                        $quote.removeAttr('id');
                                        this.wutil.setCaretAfter($quote[0]);
+                                       
+                                       // inserting a quote can spawn an additional empty newline in front
+                                       var prev = $quote[0].previousElementSibling;
+                                       if (prev !== null && prev.nodeName === 'P' && prev.innerHTML === '\u200B') {
+                                               prev = prev.previousElementSibling;
+                                               if (prev !== null && prev.nodeName === 'P' && (prev.innerHTML === '\u200B' || prev.innerHTML === '<br>')) {
+                                                       prev.parentNode.removeChild(prev.nextElementSibling);
+                                               }
+                                       }
                                }
                                
                                this.wbbcode.observeQuotes();
@@ -2373,12 +2387,12 @@ RedactorPlugins.wbbcode = function() {
                                        if (!$sibling.innerHTML.length) {
                                                $sibling.parentElement.removeChild($sibling);
                                        }
-                                       else if ($sibling.innerHTML === '\u200b') {
+                                       /*else if ($sibling.innerHTML === '\u200b') {
                                                var $adjacentSibling = $sibling[position];
                                                if ($adjacentSibling && $adjacentSibling.nodeType === Node.ELEMENT_NODE && $adjacentSibling.tagName === 'P' && $adjacentSibling.innerHTML.length) {
                                                        $sibling.parentElement.removeChild($sibling);
                                                }
-                                       }
+                                       }*/
                                }
                        }).bind(this);