Fixed check for empty paragraph after insert
authorAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 15:38:03 +0000 (17:38 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 15:38:03 +0000 (17:38 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js

index 4d4003b4deea9e707fd620a6450a79637866b6fe..f28d1c5eee37f871cf9144e2a5ffb97dcd0f17f7 100644 (file)
@@ -17,10 +17,20 @@ $.Redactor.prototype.WoltLabInsert = function() {
                                
                                mpHtml.call(this, html, data);
                                
-                               if (block && block.nodeName === 'P' && block.nextElementSibling && !block.childElementCount && block.textContent.replace(/\u200B/g, '').trim() === '') {
-                                       // inserting HTML tends to cause new paragraphs inserted
-                                       // rather than using the current, empty one
-                                       elRemove(block);
+                               if (block && block.nodeName === 'P' && block.nextElementSibling) {
+                                       var removeBlock = false;
+                                       if (block.childElementCount === 0 && block.textContent.replace(/\u200B/g, '').trim() === '') {
+                                               removeBlock = true;
+                                       }
+                                       else if (block.childElementCount === 1 && block.innerHTML === '<br>') {
+                                               removeBlock = true;
+                                       }
+                                       
+                                       if (removeBlock) {
+                                               // inserting HTML tends to cause new paragraphs inserted
+                                               // rather than using the current, empty one
+                                               elRemove(block);
+                                       }
                                }
                        }).bind(this);