From: Alexander Ebert Date: Sat, 17 Jan 2015 11:47:40 +0000 (+0100) Subject: Internally storing the implicit range instead of altering it X-Git-Tag: 2.1.0_Beta_4~83 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5271d93ec48f0241112257b52236516e2757fef8;p=GitHub%2FWoltLab%2FWCF.git Internally storing the implicit range instead of altering it The previous approach provided the actual range in effect which was great if you want to work with the real one. The only downside is that the editor itself relies on the flawed range and changing it into the real one does break stuff. --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index c35169bac6..e6b04678e7 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1450,9 +1450,10 @@ RedactorPlugins.wbbcode = function() { } } else { - var $scope = current; + var $range = (this.selection.implicitRange === null) ? this.range : this.selection.implicitRange; + var $scope = $range.startContainer; if ($scope.nodeType === Node.TEXT_NODE) { - if (this.range.startOffset === 0 || (this.range.startOffset === 1 && $scope.textContent === '\u200b')) { + if ($range.startOffset === 0 || ($range.startOffset === 1 && $scope.textContent === '\u200b')) { if (!$scope.previousSibling) { $scope = $scope.parentElement; } diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 51007c899f..c8737b9d77 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -17,6 +17,8 @@ if (!RedactorPlugins) var RedactorPlugins = {}; RedactorPlugins.wmonkeypatch = function() { "use strict"; + var $rangeBeforeRemoveMarker = null; + return { /** * Initializes the RedactorPlugins.wmonkeypatch plugin. @@ -868,6 +870,8 @@ RedactorPlugins.wmonkeypatch = function() { * - remove superflous empty text nodes caused by the selection markers (#2083) */ selection: function() { + this.selection.implicitRange = null; + var $removeEmptyTextNodes = (function(index, marker) { var $nextSibling = marker.nextSibling; if ($nextSibling !== null && $nextSibling.nodeType === Node.TEXT_NODE && $nextSibling.length === 0) { @@ -882,7 +886,12 @@ RedactorPlugins.wmonkeypatch = function() { $(marker).remove(); if ($node !== null) { - this.caret.set($node, $node.length, $node, $node.length); + this.selection.implicitRange = document.createRange(); + this.selection.implicitRange.setStart($node, $node.length); + this.selection.implicitRange.setEnd($node, $node.length); + } + else { + this.selection.implicitRange = null; } }).bind(this); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 4e8fb64fa6..1aa841b9ac 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -60,13 +60,18 @@ RedactorPlugins.wutil = function() { /** * Saves current caret position. + * + * @param boolean discardSavedIfEmpty */ - saveSelection: function() { + saveSelection: function(discardSavedIfEmpty) { var $selection = getSelection(); if ($selection.rangeCount) { this.wutil._range = $selection.getRangeAt(0); } + else if (discardSavedIfEmpty) { + this.wutil._range = null; + } }, /** @@ -90,7 +95,16 @@ RedactorPlugins.wutil = function() { * Clears the current selection. */ clearSelection: function() { - this._wutil.range = null; + this.wutil._range = null; + }, + + /** + * Returns stored selection or null. + * + * @return Range + */ + getSelection: function() { + return this.wutil._range; }, /**