Skip to content

Commit b4e5b97

Browse files
Moved iteration scope to separate file
1 parent 56172e3 commit b4e5b97

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Range,
55
type ScopeType,
66
type SurroundingPairName,
7-
testRegex,
87
type TextEditor,
98
} from "@cursorless/common";
109
import { shrinkRangeToFitContent } from "../../../../util/selectionUtils";
@@ -16,36 +15,16 @@ import type {
1615
ScopeIteratorRequirements,
1716
} from "../scopeHandler.types";
1817
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
18+
import { collectionItemIterationScopeHandler } from "./collectionItemIterationScopeHandler";
1919
import { createTargetScope } from "./createTargetScope";
20-
import {
21-
getSeparatorOccurrences,
22-
separatorRegex,
23-
} from "./getSeparatorOccurrences";
20+
import { getSeparatorOccurrences } from "./getSeparatorOccurrences";
2421

2522
export class CollectionItemTextualScopeHandler extends BaseScopeHandler {
2623
public scopeType: ScopeType = { type: "collectionItem" };
2724
protected isHierarchical = true;
2825

29-
get iterationScopeType(): ScopeType | ComplexScopeType {
30-
return {
31-
type: "fallback",
32-
scopeTypes: [
33-
{
34-
type: "surroundingPairInterior",
35-
delimiter: "collectionBoundary",
36-
},
37-
{
38-
type: "conditional",
39-
scopeType: {
40-
type: "line",
41-
},
42-
predicate: (scope: TargetScope) => {
43-
const text = scope.editor.document.getText(scope.domain);
44-
return testRegex(separatorRegex, text);
45-
},
46-
},
47-
],
48-
};
26+
get iterationScopeType(): ComplexScopeType {
27+
return collectionItemIterationScopeHandler;
4928
}
5029

5130
constructor(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { testRegex } from "@cursorless/common";
2+
import type { TargetScope } from "../scope.types";
3+
import type { ComplexScopeType } from "../scopeHandler.types";
4+
import { separatorRegex } from "./getSeparatorOccurrences";
5+
6+
export const collectionItemIterationScopeHandler: ComplexScopeType = {
7+
type: "fallback",
8+
scopeTypes: [
9+
{
10+
type: "surroundingPairInterior",
11+
delimiter: "collectionBoundary",
12+
},
13+
{
14+
type: "conditional",
15+
scopeType: {
16+
type: "line",
17+
},
18+
predicate: (scope: TargetScope) => {
19+
const text = scope.editor.document.getText(scope.domain);
20+
return testRegex(separatorRegex, text);
21+
},
22+
},
23+
],
24+
};

0 commit comments

Comments
 (0)