|
@@ -330,6 +330,17 @@ export default class Selection {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Checks whether, this selection is similar to given selection. Selections are similar if they are initially
|
|
|
|
|
+ * equal (see {@link #isEqual isEqual}) or if their trimmed (see {@link #getTrimmed getTrimmed}) representations are equal.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {module:engine/view/selection~Selection} otherSelection Selection to compare with.
|
|
|
|
|
+ * @returns {Boolean} `true` if selections are similar, `false` otherwise.
|
|
|
|
|
+ */
|
|
|
|
|
+ isSimilar( otherSelection ) {
|
|
|
|
|
+ return this.isEqual( otherSelection ) || this.getTrimmed().isEqual( otherSelection.getTrimmed() );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Removes all ranges that were added to the selection.
|
|
* Removes all ranges that were added to the selection.
|
|
|
*
|
|
*
|
|
@@ -482,6 +493,27 @@ export default class Selection {
|
|
|
return ( nodeAfterStart instanceof Element && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
|
|
return ( nodeAfterStart instanceof Element && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns a copy of a selection with all of its ranges
|
|
|
|
|
+ * trimmed (see {@link module:engine/view/range~Range#getTrimmed getTrimmed}).
|
|
|
|
|
+ *
|
|
|
|
|
+ * @returns {module:engine/view/selection~Selection} Selection with all ranges shrank.
|
|
|
|
|
+ */
|
|
|
|
|
+ getTrimmed() {
|
|
|
|
|
+ const selection = Selection.createFromSelection( this );
|
|
|
|
|
+ const ranges = this.getRanges();
|
|
|
|
|
+
|
|
|
|
|
+ let trimmedRanges = [];
|
|
|
|
|
+
|
|
|
|
|
+ for ( let range of ranges ) {
|
|
|
|
|
+ trimmedRanges.push( range.getTrimmed() );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ selection.setRanges( trimmedRanges );
|
|
|
|
|
+
|
|
|
|
|
+ return selection;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Creates and returns an instance of `Selection` that is a clone of given selection, meaning that it has same
|
|
* Creates and returns an instance of `Selection` that is a clone of given selection, meaning that it has same
|
|
|
* ranges and same direction as this selection.
|
|
* ranges and same direction as this selection.
|