From 90fffc46d58b8fb534a0032b1a8446d70fa02d63 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 19 Aug 2016 23:26:01 +0200 Subject: [PATCH] Clicking before/after a block adds an empty

if required --- .../redactor2/plugins/WoltLabCaret.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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) { -- 2.20.1