From 7fe8cf4dd216a9629fa3cbdc5113e825b141cd8e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 14 Feb 2022 17:14:00 +0100 Subject: [PATCH] Work-around for the inconsistent selection handling in iOS 15 See https://www.woltlab.com/community/thread/294136-ios-text-markieren-link-einf%C3%BCgen-geht-nicht/ --- .../3rdParty/redactor2/plugins/WoltLabLink.js | 21 +++++++++++++++++-- .../files/js/3rdParty/redactor2/redactor.js | 8 +++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js index dc233ff5d3..309bf39f33 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js @@ -66,12 +66,21 @@ $.Redactor.prototype.WoltLabLink = function() { { e.preventDefault(); } + + let hasRestoredSelection = false; + if (this.detect.isMobile() && !this.core.editor()[0].contains(document.activeElement)) { + this.selection.restore(); + + hasRestoredSelection = true; + } // used to determine if selection needs to be restored later as // Safari sometimes discards the selection when setting markers var hasSelectedText = this.selection.is(); - this.selection.save(); + if (!hasRestoredSelection) { + this.selection.save(); + } // close tooltip this.observe.closeAllTooltip(); @@ -79,6 +88,14 @@ $.Redactor.prototype.WoltLabLink = function() { // is link //var $el = this.link.is(); var $el = $link || false; + + if (hasRestoredSelection) { + if ($el === false) { + $el = this.link.is(); + } + + document.activeElement.blur(); + } // build link if (hasSelectedText) this.selection.restore(); @@ -101,7 +118,7 @@ $.Redactor.prototype.WoltLabLink = function() { this.selection.restore(); // insert or update - this.link.insert(link, true); + this.link.insert(link, true, $el); return true; }).bind(this) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js index 7d9e69e528..e51bf08f30 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js @@ -3564,6 +3564,10 @@ require(['Ui/SimpleDropdown'], (function(UiSimpleDropdown) { var dropdownId = this.dropdown.button[0].id; + + if (this.detect.isMobile() && !UiSimpleDropdown.isOpen(dropdownId)) { + this.selection.save(); + } UiSimpleDropdown.toggleDropdown(dropdownId); if (UiSimpleDropdown.isOpen(dropdownId)) { @@ -6677,8 +6681,8 @@ this.core.callback('deletedLink', $links); }, - insert: function (link, cleaned) { - var $el = this.link.is(); + insert: function (link, cleaned, savedLink) { + var $el = savedLink || this.link.is(); if (cleaned !== true) { link = this.link.buildLinkFromObject($el, link); -- 2.20.1