Fixed code insert if editor was never active
authorAlexander Ebert <ebert@woltlab.com>
Sat, 18 Jun 2016 12:21:38 +0000 (14:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 18 Jun 2016 12:21:38 +0000 (14:21 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js

index 8c61a5169e590e478e3335382cfa5e3646f1a2c0..81453a2085726cc701c7d32c401356188e9d2f14 100644 (file)
@@ -749,17 +749,25 @@ RedactorPlugins.wutil = function() {
                                this.wutil.restoreSelection();
                        }
                        
+                       // check if selection is actually within editor
+                       var startContainer = getSelection().getRangeAt(0).startContainer;
+                       if (startContainer !== this.$editor[0] && !this.utils.isRedactorParent(startContainer)) {
+                               // selection is somewhere else
+                               this.wutil.selectionEndOfEditor();
+                       }
+                       
+                       
                        if (getSelection().getRangeAt(0).collapsed) {
-                               var $startContainer = getSelection().getRangeAt(0).startContainer;
-                               if ($startContainer.nodeType === Node.TEXT_NODE && $startContainer.textContent === '\u200b' && $startContainer.parentElement && $startContainer.parentElement.tagName === 'P' && $startContainer.parentElement.parentElement === this.$editor[0]) {
+                               startContainer = getSelection().getRangeAt(0).startContainer;
+                               if (startContainer.nodeType === Node.TEXT_NODE && startContainer.textContent === '\u200b' && startContainer.parentElement && startContainer.parentElement.tagName === 'P' && startContainer.parentElement.parentElement === this.$editor[0]) {
                                        // caret position is fine
                                        return;
                                }
                                else {
                                        // walk tree up until we find a direct children of the editor and place the caret afterwards
-                                       var $insertAfter = $startContainer;
+                                       var $insertAfter = startContainer;
                                        if ($insertAfter !== this.$editor[0]) {
-                                               $startContainer = $($startContainer).parentsUntil(this.$editor[0]).last();
+                                               $insertAfter = $(startContainer).parentsUntil(this.$editor[0]).last();
                                        }
                                        
                                        if ($insertAfter[0] === document.body.parentElement) {