Skip to content

Commit 951b947

Browse files
Merge with main
1 parent e61b532 commit 951b947

File tree

9 files changed

+16
-109
lines changed

9 files changed

+16
-109
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/CollectionItemTextualScopeHandler.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import type {
1414
ScopeIteratorRequirements,
1515
} from "../scopeHandler.types";
1616
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
17+
import { OneWayNestedRangeFinder } from "../util/OneWayNestedRangeFinder";
18+
import { OneWayRangeFinder } from "../util/OneWayRangeFinder";
1719
import { collectionItemIterationScopeHandler } from "./collectionItemIterationScopeHandler";
18-
import { createRangeTree } from "./createRangeTree";
1920
import { createTargetScope } from "./createTargetScope";
2021
import { getInteriorRanges } from "./getInteriorRanges";
2122
import { getSeparatorOccurrences } from "./getSeparatorOccurrences";
22-
import { RangeIterator } from "./RangeIterator";
2323

2424
export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
2525
public scopeType: ScopeType = { type: "collectionItem" };
@@ -50,33 +50,30 @@ export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
5050
editor,
5151
"collectionBoundary",
5252
);
53-
const interiorRangeIterator = new RangeIterator(
54-
createRangeTree(interiorRanges),
55-
);
53+
const interiorRangeFinder = new OneWayNestedRangeFinder(interiorRanges);
5654
const stringRanges = getInteriorRanges(
5755
this.scopeHandlerFactory,
5856
this.languageId,
5957
editor,
6058
"string",
6159
);
62-
const stringRangeIterator = new RangeIterator(stringRanges);
60+
const stringRangeFinder = new OneWayRangeFinder(stringRanges);
6361
const scopes: TargetScope[] = [];
6462
const usedInteriors = new Set<Range>();
6563
const iterationStatesStack: IterationState[] = [];
6664

6765
for (const separator of separatorRanges) {
6866
// Separators in a string are not considered
69-
if (stringRangeIterator.contains(separator)) {
67+
if (stringRangeFinder.contains(separator)) {
7068
continue;
7169
}
7270

7371
const currentIterationState =
7472
iterationStatesStack[iterationStatesStack.length - 1];
7573

7674
// Get range for smallest containing interior
77-
const containingInteriorRange = interiorRangeIterator
78-
.getContaining(separator)
79-
?.getSmallLestContaining(separator);
75+
const containingInteriorRange =
76+
interiorRangeFinder.getSmallestContaining(separator)?.range;
8077

8178
// The contain range is either the interior or the line containing the separator
8279
const containingIterationRange =
@@ -130,10 +127,12 @@ export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
130127

131128
// Add interior ranges without a delimiter in them. eg: `[foo]`
132129
for (const interior of interiorRanges) {
133-
if (!usedInteriors.has(interior)) {
134-
const range = shrinkRangeToFitContent(editor, interior);
130+
if (!usedInteriors.has(interior.range)) {
131+
const range = shrinkRangeToFitContent(editor, interior.range);
135132
if (!range.isEmpty) {
136-
scopes.push(createTargetScope(isEveryScope, editor, interior, range));
133+
scopes.push(
134+
createTargetScope(isEveryScope, editor, interior.range, range),
135+
);
137136
}
138137
}
139138
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/RangeIterator.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/RangeNode.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/createRangeTree.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/getInteriorRanges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function getInteriorRanges(
1111
languageId: string,
1212
editor: TextEditor,
1313
delimiter: SurroundingPairName,
14-
): Range[] {
14+
): { range: Range }[] {
1515
const scopeHandler = scopeHandlerFactory.create(
1616
{
1717
type: "surroundingPairInterior",
@@ -26,6 +26,6 @@ export function getInteriorRanges(
2626
skipAncestorScopes: false,
2727
includeDescendantScopes: true,
2828
}),
29-
(scope) => scope.domain,
29+
(scope) => ({ range: scope.domain }),
3030
);
3131
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getDelimiterOccurrences.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
} from "@cursorless/common";
77
import type { LanguageDefinition } from "../../../../languages/LanguageDefinition";
88
import type { QueryCapture } from "../../../../languages/TreeSitterQuery/QueryCapture";
9+
import { OneWayNestedRangeFinder } from "../util/OneWayNestedRangeFinder";
10+
import { OneWayRangeFinder } from "../util/OneWayRangeFinder";
911
import { getDelimiterRegex } from "./getDelimiterRegex";
10-
import { OneWayRangeFinder } from "./OneWayRangeFinder";
11-
import { OneWayNestedRangeFinder } from "./OneWayNestedRangeFinder";
1212
import type { DelimiterOccurrence, IndividualDelimiter } from "./types";
1313

1414
/**

0 commit comments

Comments
 (0)