Skip to content

Commit 23ecc35

Browse files
Extract get interior ranges to separate file
1 parent b4e5b97 commit 23ecc35

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

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

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {
22
type Direction,
3-
Position,
3+
type Position,
44
Range,
55
type ScopeType,
6-
type SurroundingPairName,
76
type TextEditor,
87
} from "@cursorless/common";
98
import { shrinkRangeToFitContent } from "../../../../util/selectionUtils";
@@ -17,6 +16,7 @@ import type {
1716
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
1817
import { collectionItemIterationScopeHandler } from "./collectionItemIterationScopeHandler";
1918
import { createTargetScope } from "./createTargetScope";
19+
import { getInteriorRanges } from "./getInteriorRanges";
2020
import { getSeparatorOccurrences } from "./getSeparatorOccurrences";
2121

2222
export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
@@ -34,27 +34,6 @@ export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
3434
super();
3535
}
3636

37-
private getInteriorRanges(
38-
editor: TextEditor,
39-
delimiter: SurroundingPairName,
40-
): Range[] {
41-
const scopeHandler = this.scopeHandlerFactory.create(
42-
{
43-
type: "surroundingPairInterior",
44-
delimiter,
45-
},
46-
this.languageId,
47-
);
48-
return Array.from(
49-
scopeHandler.generateScopes(editor, new Position(0, 0), "forward", {
50-
containment: undefined,
51-
skipAncestorScopes: false,
52-
includeDescendantScopes: true,
53-
}),
54-
(scope) => scope.domain,
55-
);
56-
}
57-
5837
*generateScopeCandidates(
5938
editor: TextEditor,
6039
position: Position,
@@ -63,8 +42,18 @@ export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
6342
): Iterable<TargetScope> {
6443
const isEveryScope = hints.containment == null && hints.skipAncestorScopes;
6544
const separatorRanges = getSeparatorOccurrences(editor.document);
66-
const interiorRanges = this.getInteriorRanges(editor, "collectionBoundary");
67-
const stringRanges = this.getInteriorRanges(editor, "string");
45+
const interiorRanges = getInteriorRanges(
46+
this.scopeHandlerFactory,
47+
this.languageId,
48+
editor,
49+
"collectionBoundary",
50+
);
51+
const stringRanges = getInteriorRanges(
52+
this.scopeHandlerFactory,
53+
this.languageId,
54+
editor,
55+
"string",
56+
);
6857
const scopes: TargetScope[] = [];
6958
const usedInteriors = new Set<Range>();
7059
const iterationStatesStack: IterationState[] = [];
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
type Range,
3+
type SurroundingPairName,
4+
type TextEditor,
5+
Position,
6+
} from "@cursorless/common";
7+
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
8+
9+
export function getInteriorRanges(
10+
scopeHandlerFactory: ScopeHandlerFactory,
11+
languageId: string,
12+
editor: TextEditor,
13+
delimiter: SurroundingPairName,
14+
): Range[] {
15+
const scopeHandler = scopeHandlerFactory.create(
16+
{
17+
type: "surroundingPairInterior",
18+
delimiter,
19+
},
20+
languageId,
21+
);
22+
return Array.from(
23+
scopeHandler.generateScopes(editor, new Position(0, 0), "forward", {
24+
containment: undefined,
25+
skipAncestorScopes: false,
26+
includeDescendantScopes: true,
27+
}),
28+
(scope) => scope.domain,
29+
);
30+
}

0 commit comments

Comments
 (0)