Fixed safari focusing without providing a range
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Jan 2017 10:53:12 +0000 (11:53 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Jan 2017 10:53:12 +0000 (11:53 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 539be732ef37bceaaf060b6267e9a265d4fd6247..2053268f3e9c875eeda59fbaff36b63ff0562bb5 100644 (file)
@@ -796,12 +796,13 @@ RedactorPlugins.wmonkeypatch = function() {
                                        }
                                }
                                else {
-                                       if (document.activeElement !== this.$editor[0]) {
+                                       var $selection = window.getSelection();
+                                       if (document.activeElement !== this.$editor[0] || $selection.rangeCount === 0) {
                                                this.wutil.restoreSelection();
                                        }
                                        
-                                       if (html.match(/^<(blockquote|div|p)/i) && getSelection().getRangeAt(0).collapsed) {
-                                               var $startContainer = getSelection().getRangeAt(0).startContainer;
+                                       if (html.match(/^<(blockquote|div|p)/i) && $selection.getRangeAt(0).collapsed) {
+                                               var $startContainer = $selection.getRangeAt(0).startContainer;
                                                if ($startContainer.nodeType === Node.TEXT_NODE && $startContainer.textContent === '\u200b') {
                                                        // Safari breaks if inserting block-level elements into a <p /> w/ only a zero-width space
                                                        this.caret.setEnd($($startContainer.parentElement).html('<br />'));