Skip bogus selection changes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 20 Sep 2021 16:25:10 +0000 (18:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 20 Sep 2021 16:25:10 +0000 (18:25 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 61130a3b050838244ca00d386a6179604a1cbf2f..4d2f5a6c586e5384e061f37ac701c3cbc843e220 100644 (file)
@@ -619,6 +619,14 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        var anchorNode, sibling;
                        
                        var selection = window.getSelection();
+                       if (!selection.rangeCount) {
+                               // Skip invocations that do not have an active range. This happens if the
+                               // user loads a page but has not yet interacted with the page. Such a
+                               // selection is the result of a synthetic event without any prior user
+                               // interaction.
+                               return;
+                       }
+
                        if (!selection.isCollapsed) {
                                if (_isSafari && _iOS && _touchstartTarget === event.target && this.utils.isBlockTag(_touchstartTarget.nodeName)) {
                                        // Treat this as a collapsed selection instead, because the iOS Safari