From 2f57a2e1c9d8f7e2c73015472ad88de0215ca14e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 10 Feb 2020 18:56:23 +0100 Subject: [PATCH] iOS Safari bug that cripples the editor after backspacing an empty instance --- .../files/js/3rdParty/redactor2/redactor.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js index 06d0299b3b..a3a9fd842a 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js @@ -6353,8 +6353,25 @@ this.selection.restore(); } else { - this.core.editor().html(this.opts.emptyHtml); - this.focus.start(); + var updateHtml = function() { + this.core.editor().html(this.opts.emptyHtml); + this.focus.start(); + }.bind(this); + + if (Environment !== null && Environment.platform() === 'ios') { + // In iOS Safari the backspace sometimes appears to be triggered twice if the editor + // is completely empty. After debugging for way too much time, and realizing that + // the remote debugger's breakpoints alter the behavior of async callbacks (*), this + // should solve the issue. + // + // (*) Set up a `console.log()` inside a MutationObserver and then make use of the + // `debugger;` statement to halt the execution flow. The observer is executed, but + // the output never appears on the console. Output works if there is no breakpoint. + setTimeout(updateHtml, 50); + } + else { + updateHtml(); + } } return false; -- 2.20.1