Workaround for iOS Safari's caret placement in empty <p>
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2019 16:09:50 +0000 (18:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2019 16:09:50 +0000 (18:09 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js

index c7d1950e194d0476b11ac0df165c0bc58289d652..e324bd5a1fee8dbfb46796838c00cd870e751048 100644 (file)
@@ -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 = '<br>';
+                                       }
+                               }
+                               
+                               mpStart.call(this, node);
+                       }).bind(this);
+                       
                        var editor = this.core.editor()[0];
                        require(['Environment'], (function (Environment) {
                                _iOS = (Environment.platform() === 'ios');
index c4e3812e529ba22c5331113ce774ec53702523c9..6ff3dcd06969207b6735a2a60b9953c2c1982805 100644 (file)
@@ -307,4 +307,4 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
        };
        
        return UiRedactorQuote;
-});
\ No newline at end of file
+});