Avoid incorrect selection handling w/o a selection
authorAlexander Ebert <ebert@woltlab.com>
Fri, 9 Feb 2018 12:57:13 +0000 (13:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 9 Feb 2018 12:57:13 +0000 (13:57 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 9934f2e8ab364644f534e3637aa061e8aae2a64e..1d3d4463bf5b9b1ff3fa92721bdc85656d9b0d71 100644 (file)
@@ -91,13 +91,15 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        this.selection.saveInstant = (function() {
                                mpSaveInstant.call(this);
                                
-                               this.saved.isAtNodeStart = false;
-                               
-                               var selection = window.getSelection();
-                               if (selection.rangeCount && !selection.isCollapsed) {
-                                       var range = selection.getRangeAt(0);
-                                       if (range.startContainer.nodeType === Node.TEXT_NODE && range.startOffset === 0) {
-                                               this.saved.isAtNodeStart = true;
+                               if (this.saved) {
+                                       this.saved.isAtNodeStart = false;
+                                       
+                                       var selection = window.getSelection();
+                                       if (selection.rangeCount && !selection.isCollapsed) {
+                                               var range = selection.getRangeAt(0);
+                                               if (range.startContainer.nodeType === Node.TEXT_NODE && range.startOffset === 0) {
+                                                       this.saved.isAtNodeStart = true;
+                                               }
                                        }
                                }
                        }).bind(this);