From: Alexander Ebert Date: Mon, 29 Dec 2014 13:54:29 +0000 (+0100) Subject: Improved inserting of quotes X-Git-Tag: 2.1.0_Beta_3~59 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b90a83ef289d4f9e8b6af26145532eb324ae01d7;p=GitHub%2FWoltLab%2FWCF.git Improved inserting of quotes --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 0ed9cf7e67..2a87d6e61c 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -599,6 +599,32 @@ RedactorPlugins.wutil = function() { this.wutil.saveSelection(); }, + /** + * Inserting block-level elements into other blocks or inline elements can mess up the entire DOM, + * this method tries to find the best insert location nearby. + */ + adjustSelectionForBlockElement: function() { + if (document.activeElement !== this.$editor[0]) { + this.wutil.restoreSelection(); + } + + if (getSelection().getRangeAt(0).collapsed) { + var $startContainer = getSelection().getRangeAt(0).startContainer; + if ($startContainer.nodeType === Node.TEXT_NODE && $startContainer.textContent === '\u200b' && $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).parentsUntil(this.$editor[0]).last(); + var $p = $('


').insertAfter($insertAfter); + + this.caret.setEnd($p); + } + } + }, + /** * Returns true if current selection is just a caret or false if selection spans content. * diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 0500ebbdbd..8454828b30 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -834,7 +834,7 @@ WCF.Message.QuickReply = Class.extend({ } if ($insertQuote) { - this._messageField.redactor('wutil.selectionEndOfEditor'); + this._messageField.redactor('wutil.adjustSelectionForBlockElement'); this._messageField.redactor('wbbcode.insertQuoteBBCode', data.quote.username, data.quote.link, data.quote.text, data.quote.text); // scroll to editor