From dd829b643d403f403fae8748a8f00e2e448af490 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 27 Jun 2022 18:53:37 +0200 Subject: [PATCH] Force restore saved selections after inserting links into the editor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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/ --- .../files/js/3rdParty/redactor2/plugins/WoltLabLink.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js index 6ec4016b34..89ad814ba7 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js @@ -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); -- 2.20.1