From abb354c9acac65c99ed499f7aa9b768c4cf30cff Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 20 May 2017 14:40:48 +0200 Subject: [PATCH] Fixed table selection and erroneous whitespaces --- .../3rdParty/redactor2/plugins/WoltLabTable.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js index 06fed1941e..bdb51a3283 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js @@ -5,10 +5,21 @@ $.Redactor.prototype.WoltLabTable = function() { init: function() { this.WoltLabEvent.register('insertedTable', (function() { window.setTimeout((function () { - var node = this.selection.block() || this.selection.current(); - if (node.nodeName === 'TBODY') { + var table = this.selection.block() || this.selection.current(); + if (table.nodeName === 'TBODY') table = table.parentNode; + if (table.nodeName === 'TABLE') { + // remove whitespaces directly inside the table element + var node, textNodes = []; + for (var i = 0, length = table.childNodes.length; i < length; i++) { + node = table.childNodes[i]; + if (node.nodeType === Node.TEXT_NODE && node.textContent.length > 0) { + textNodes.push(node); + } + } + textNodes.forEach(elRemove); + // find first and set the caret inside it - var td = elBySel('td', node); + var td = elBySel('td', table); if (td) { this.caret.end(td); } -- 2.20.1