From 9aaff880a9577bddaaadac65e5fed02f47588371 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 8 Jul 2019 18:09:50 +0200 Subject: [PATCH] Workaround for iOS Safari's caret placement in empty

--- .../redactor2/plugins/WoltLabCaret.js | 19 +++++++++++++++++++ .../js/WoltLabSuite/Core/Ui/Redactor/Quote.js | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js index c7d1950e19..e324bd5a1f 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js @@ -18,6 +18,25 @@ $.Redactor.prototype.WoltLabCaret = function() { mpAfter.call(this, node); }).bind(this); + var mpStart = this.caret.start; + this.caret.start = (function (node) { + if (_isSafari && _iOS) { + var sel, range; + node = this.caret.prepare(node); + + if (!node) { + return; + } + + // iOS Safari offsets the caret by a half if the only content is an invisible space. + if (node.nodeName === 'P' && node.innerHTML === '\u200b') { + node.innerHTML = '
'; + } + } + + mpStart.call(this, node); + }).bind(this); + var editor = this.core.editor()[0]; require(['Environment'], (function (Environment) { _iOS = (Environment.platform() === 'ios'); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js index c4e3812e52..6ff3dcd069 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -307,4 +307,4 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' }; return UiRedactorQuote; -}); \ No newline at end of file +}); -- 2.20.1