From: Alexander Ebert Date: Thu, 22 Sep 2016 18:21:40 +0000 (+0200) Subject: Append whitespace after `` X-Git-Tag: 3.0.0_Beta_1~23 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=220df450c5578d3361c5dbd80d66d14baf91e86c;p=GitHub%2FWoltLab%2FWCF.git Append whitespace after `` It behaves exactly like any other inline format (e.g. bold or italic), but people expect it to behave more like a block element. Meh. --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInlineCode.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInlineCode.js index a60646f477..ad383b8fc3 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInlineCode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInlineCode.js @@ -6,12 +6,35 @@ $.Redactor.prototype.WoltLabInlineCode = function() { this.opts.activeButtonsStates.kbd = 'tt'; require(['EventHandler'], (function (EventHandler) { - EventHandler.add('com.woltlab.wcf.redactor2', 'bbcode_tt_' + this.$element[0].id, (function(data) { - data.cancel = true; - - this.button.toggle({}, 'kbd', 'func', 'inline.format'); - }).bind(this)); + EventHandler.add('com.woltlab.wcf.redactor2', 'bbcode_tt_' + this.$element[0].id, this.WoltLabInlineCode._toggle.bind(this)); }).bind(this)); + }, + + _toggle: function (data) { + data.cancel = true; + + this.button.toggle({}, 'kbd', 'func', 'inline.format'); + + var node = window.getSelection().anchorNode; + if (node.nodeType === Node.TEXT_NODE) node = node.parentNode; + + if (node.nodeName === 'KBD') { + var nextSibling = node.nextSibling; + while (nextSibling) { + if (nextSibling.nodeType !== Node.TEXT_NODE || nextSibling.textContent.length) { + return; + } + + nextSibling = nextSibling.nextSibling; + } + + if (nextSibling) { + nextSibling.textContent = '\u200B'; + } + else { + node.parentNode.appendChild(document.createTextNode('\u200B')); + } + } } }; };