From 88e375c959cde08c707182f5effccacd5308a0d1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 7 Sep 2016 13:03:49 +0200 Subject: [PATCH] Fixed text alignment lost on new line --- .../redactor2/plugins/WoltLabKeydown.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index 05b68f50cb..d774fb5849 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -37,6 +37,39 @@ $.Redactor.prototype.WoltLabKeydown = function() { if (isBlockquote) this.keydown.blockquote = isBlockquote; }).bind(this); + this.keydown.replaceToParagraph = (function(tag) { + var blockElem = this.selection.block(); + + var blockHtml = blockElem.innerHTML.replace(//gi, ''); + if (blockElem.tagName === tag && this.utils.isEmpty(blockHtml) && !$(blockElem).hasClass('redactor-in')) + { + var p = document.createElement('p'); + $(blockElem).replaceWith(p); + + // caret to p + var range = document.createRange(); + range.setStart(p, 0); + + var textNode = document.createTextNode('\u200B'); + + range.insertNode(textNode); + range.setStartAfter(textNode); + range.collapse(true); + + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + + return false; + } + else if (blockElem.tagName === 'P') + { + // WoltLab modification: do not remove class, preserving + // text alignment + $(blockElem)/*.removeAttr('class')*/.removeAttr('style'); + } + }).bind(this); + this.keydown.onShiftEnter = (function(e) { this.buffer.set(); -- 2.20.1