Force restore saved selections after inserting links into the editor
authorAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jun 2022 16:53:37 +0000 (18:53 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jun 2022 16:53:37 +0000 (18:53 +0200)
Redactor‘s selection handling is very fragile and “forgetting” to restore the selection can cause some very strange side-effects.

The user will start typing inside a selection marker, which will not cause any visual effects, but the content will get lost once the editor removes the markers.

See https://www.woltlab.com/community/thread/296022-einf%C3%BCgen-von-links-im-editor-unter-ipados/
See https://www.woltlab.com/community/thread/296116-einf%C3%BCgen-von-links-im-editor-unter-ipados-text-verschwindet/
See https://www.woltlab.com/community/thread/294753-text-wird-beim-speichern-abgeschnitten/

wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js

index 6ec4016b341cf571e95243b927820dfcd50086b1..89ad814ba7fa0c7ce365dfd24ca945e228900659 100644 (file)
@@ -121,8 +121,15 @@ $.Redactor.prototype.WoltLabLink = function() {
                                        this.selection.save();
 
                                        // Closing the dialog might move the focus somewhere else.
+                                       //
+                                       // On iPadOS the focus handling is inconsistent with iOS and
+                                       // causes the marker to persist in the editor, causing strange
+                                       // side-effects.
                                        window.setTimeout(() => {
-                                               if (document.activeElement !== this.core.editor()[0]) {
+                                               if (
+                                                       document.activeElement !== this.core.editor()[0]
+                                                       || this.core.editor()[0].querySelector(".redactor-selection-marker") !== null
+                                               ) {
                                                        this.selection.restore();
                                                }
                                        }, 0);