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.
}
}
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;
}
RedactorPlugins.wmonkeypatch = function() {
"use strict";
+ var $rangeBeforeRemoveMarker = null;
+
return {
/**
* Initializes the RedactorPlugins.wmonkeypatch plugin.
* - 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) {
$(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);
/**
* 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;
+ }
},
/**
* 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;
},
/**