@adecore/editor-core 0.49.5 → 0.49.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/document.js CHANGED
@@ -1980,9 +1980,16 @@ export class DocumentModel {
1980
1980
  for (const range of this.structure()) {
1981
1981
  candidates.push({ from: range.innerFrom, to: range.innerTo }, range);
1982
1982
  }
1983
- return candidates
1984
- .filter((range) => range.from <= from && range.to >= to && (range.from < from || range.to > to))
1985
- .sort((left, right) => left.to - left.from - (right.to - right.from))[0];
1983
+ let smallest;
1984
+ for (const range of candidates) {
1985
+ if (range.from > from || range.to < to || (range.from === from && range.to === to)) {
1986
+ continue;
1987
+ }
1988
+ if (smallest === undefined || range.to - range.from < smallest.to - smallest.from) {
1989
+ smallest = range;
1990
+ }
1991
+ }
1992
+ return smallest;
1986
1993
  }
1987
1994
  shrinkSelection() {
1988
1995
  const previous = this.selectionHistory.pop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/editor-core",
3
- "version": "0.49.5",
3
+ "version": "0.49.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/document.ts CHANGED
@@ -2778,9 +2778,19 @@ export class DocumentModel {
2778
2778
  candidates.push({ from: range.innerFrom, to: range.innerTo }, range);
2779
2779
  }
2780
2780
 
2781
- return candidates
2782
- .filter((range) => range.from <= from && range.to >= to && (range.from < from || range.to > to))
2783
- .sort((left, right) => left.to - left.from - (right.to - right.from))[0];
2781
+ let smallest: OffsetRange | undefined;
2782
+
2783
+ for (const range of candidates) {
2784
+ if (range.from > from || range.to < to || (range.from === from && range.to === to)) {
2785
+ continue;
2786
+ }
2787
+
2788
+ if (smallest === undefined || range.to - range.from < smallest.to - smallest.from) {
2789
+ smallest = range;
2790
+ }
2791
+ }
2792
+
2793
+ return smallest;
2784
2794
  }
2785
2795
 
2786
2796
  private shrinkSelection(): boolean {