From: Alexander Ebert Date: Fri, 19 Aug 2016 21:26:01 +0000 (+0200) Subject: Clicking before/after a block adds an empty

if required X-Git-Tag: 3.0.0_Beta_1~647 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=90fffc46d58b8fb534a0032b1a8446d70fa02d63;p=GitHub%2FWoltLab%2FWCF.git Clicking before/after a block adds an empty

if required --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js index 6c96331f38..7c06b841d1 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js @@ -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) {