From: Alexander Ebert Date: Sat, 18 Jun 2016 12:21:38 +0000 (+0200) Subject: Fixed code insert if editor was never active X-Git-Tag: 3.0.0_Beta_1~117^2~78 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2fced9e5105113c7c238a73395835de720105a67;p=GitHub%2FWoltLab%2FWCF.git Fixed code insert if editor was never active --- 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) {