Clicking before/after a block adds an empty <p> if required
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 21:26:01 +0000 (23:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 21:26:07 +0000 (23:26 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 6c96331f38b5b75d87df03e29f6f9ffd9034b857..7c06b841d1de79b818a7f12d59bc5b9a8ad60fc4 100644 (file)
@@ -13,6 +13,35 @@ $.Redactor.prototype.WoltLabCaret = function() {
                                
                                mpAfter.call(this, node);
                        }).bind(this);
+                       
+                       this.$editor[0].addEventListener('mouseup', this.WoltLabCaret._handleEditorClick.bind(this));
+               },
+               
+               _handleEditorClick: function (event) {
+                       if (event.target !== this.$editor[0]) {
+                               return;
+                       }
+                       
+                       if (!this.selection.get().isCollapsed) {
+                               return;
+                       }
+                       
+                       var block = this.selection.block();
+                       if (block === false) {
+                               return;
+                       }
+                       
+                       if (block.nodeName === 'P') {
+                               return;
+                       }
+                       
+                       // click occurred onto the empty editor space, but before or after a block element
+                       var insertBefore = (event.clientY < block.getBoundingClientRect().top);
+                       var p = elCreate('p');
+                       p.textContent = '\u200B';
+                       block.parentNode.insertBefore(p, (insertBefore ? block : block.nextSibling));
+                       
+                       this.caret.end(p);
                },
                
                _addParagraphAfterBlock: function (block) {