iOS Safari bug that cripples the editor after backspacing an empty instance
authorAlexander Ebert <ebert@woltlab.com>
Mon, 10 Feb 2020 17:56:23 +0000 (18:56 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 10 Feb 2020 17:56:23 +0000 (18:56 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/redactor.js

index 06d0299b3bdd0f27aeb4e12d9ad6742d2f48eae0..a3a9fd842a70e421c60eaad4b20ec65018bb343b 100644 (file)
                                                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;