From c478b69214e544b02e06b3a27fd259795fe033c9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 15 Jan 2017 18:10:50 +0100 Subject: [PATCH] Improved handling of empty `` in Firefox --- .../redactor2/plugins/WoltLabClean.js | 8 ++++++++ .../redactor2/plugins/WoltLabKeydown.js | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index b794e1d111..cc9eb262f5 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -30,6 +30,14 @@ $.Redactor.prototype.WoltLabClean = function() { } }); + // each `` must at least contain \u200B, otherwise + // Firefox will be unable to place the caret inside + elBySelAll('td', div, function (td) { + if (td.childNodes.length === 0) { + td.innerHTML = '\u200B'; + } + }); + html = div.innerHTML; return html; diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index 987e46f490..59e4138e46 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -369,7 +369,24 @@ $.Redactor.prototype.WoltLabKeydown = function() { var firefoxHandleBackspace = (function(e) { var parent; var block = this.selection.block(); - if (block.nodeName.indexOf('-') !== -1 && isEmpty(block)) { + if (!block) { + return; + } + + if (block.nodeName === 'TD') { + var html = block.innerHTML; + if (html === '\u200B') { + // backspacing the `\u200B` will break Firefox + e.preventDefault(); + } + else if (html === '') { + // Firefox already broke itself, try to recover + e.preventDefault(); + + block.innerHTML = '\u200B'; + } + } + else if (block.nodeName.indexOf('-') !== -1 && isEmpty(block)) { // backspacing an entire block parent = block.parentNode; parent.insertBefore(this.marker.get(), block.nextSibling); -- 2.20.1