From 2fced9e5105113c7c238a73395835de720105a67 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 18 Jun 2016 14:21:38 +0200 Subject: [PATCH] Fixed code insert if editor was never active --- .../files/js/3rdParty/redactor/plugins/wutil.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 8c61a5169e..81453a2085 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -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) { -- 2.20.1