Only add paragraph before/after block if there is none
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 10:41:38 +0000 (12:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 13:15:19 +0000 (15:15 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 45ae8a2ac00ef8e654cf83381e86b5119ff57bcb..b108e5108bb1b96166441b50637ec468cba32d19 100644 (file)
@@ -171,10 +171,17 @@ $.Redactor.prototype.WoltLabCaret = function() {
                                return;
                        }
                        
-                       this.buffer.set();
-                       
                        // click occurred onto the empty editor space, but before or after a block element
                        var insertBefore = (event.clientY < block.getBoundingClientRect().top);
+                       
+                       // check if there is already a paragraph in place
+                       var sibling = block[(insertBefore ? 'previous' : 'next') + 'ElementSibling'];
+                       if (sibling && sibling.nodeName === 'P') {
+                               return;
+                       }
+                       
+                       this.buffer.set();
+                       
                        var p = elCreate('p');
                        p.textContent = '\u200B';
                        block.parentNode.insertBefore(p, (insertBefore ? block : block.nextSibling));