From 712cba98a028043aa329e89bba918519caeacfef Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Aug 2016 11:52:41 +0200 Subject: [PATCH] Fixed empty paragraphs after paste --- com.woltlab.wcf/templates/wysiwyg.tpl | 2 ++ .../redactor2/plugins/WoltLabInsert.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 4abf9700cb..c26711b263 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -21,6 +21,7 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabEvent.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabImage.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInlineCode.js?v={@LAST_UPDATE_TIME}', + '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}', @@ -171,6 +172,7 @@ 'WoltLabEvent', 'WoltLabImage', 'WoltLabInlineCode', + 'WoltLabInsert', 'WoltLabLink', 'WoltLabModal', 'WoltLabPaste', diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js new file mode 100644 index 0000000000..2a220a5051 --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js @@ -0,0 +1,24 @@ +$.Redactor.prototype.WoltLabInsert = function() { + "use strict"; + + return { + init: function () { + var mpHtml = this.insert.html; + this.insert.html = (function (html, data) { + this.placeholder.hide(); + this.core.editor().focus(); + + /** @var Element */ + var block = this.selection.block(); + + 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); + } + }).bind(this); + } + }; +}; -- 2.20.1