Skip to content

Commit 7a9620f

Browse files
More clean up
1 parent b8565a7 commit 7a9620f

File tree

2 files changed

+56
-51
lines changed

2 files changed

+56
-51
lines changed

packages/common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ export interface CustomRegexScopeType {
229229

230230
export interface InteriorScopeType {
231231
type: "interior";
232+
233+
// The user has specified a scope type. eg "inside element".
232234
explicitScopeType?: boolean;
233235
}
234236

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

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,20 @@ import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
2020

2121
export class InteriorScopeHandler extends BaseScopeHandler {
2222
protected isHierarchical = true;
23-
private scopeHandler: ScopeHandler | undefined;
24-
25-
get iterationScopeType(): ScopeType | ComplexScopeType {
26-
throw new NoContainingScopeError("Iteration scope for interior");
27-
}
2823

2924
constructor(
3025
private scopeHandlerFactory: ScopeHandlerFactory,
31-
languageDefinitions: LanguageDefinitions,
32-
public scopeType: InteriorScopeType,
26+
private languageDefinitions: LanguageDefinitions,
27+
public readonly scopeType: InteriorScopeType,
3328
private languageId: string,
3429
) {
3530
super();
31+
}
3632

37-
this.scopeHandler = (() => {
38-
const languageScopeHandler = languageDefinitions
39-
.get(languageId)
40-
?.getScopeHandler(this.scopeType);
41-
42-
// If the scope type is explicit (ie, the user has specified a scope
43-
// type), then we don't want to include matching pairs. The user might
44-
// have said something like "inside element" and then we don't want to
45-
// yield the interior of the `<div>` pair.
46-
if (scopeType.explicitScopeType) {
47-
if (languageScopeHandler == null) {
48-
return undefined;
49-
}
50-
return languageScopeHandler;
51-
}
52-
53-
const pairInteriorScopeHandler = scopeHandlerFactory.create(
54-
{
55-
type: "surroundingPairInterior",
56-
delimiter: "any",
57-
allowWeakContainment: true,
58-
},
59-
languageId,
60-
);
61-
62-
if (languageScopeHandler == null) {
63-
return pairInteriorScopeHandler;
64-
}
65-
66-
return OneOfScopeHandler.createFromScopeHandlers(
67-
scopeHandlerFactory,
68-
{
69-
type: "oneOf",
70-
scopeTypes: [
71-
languageScopeHandler.scopeType,
72-
pairInteriorScopeHandler.scopeType!,
73-
],
74-
},
75-
[languageScopeHandler, pairInteriorScopeHandler],
76-
languageId,
77-
);
78-
})();
33+
get iterationScopeType(): ScopeType | ComplexScopeType {
34+
throw new NoContainingScopeError(
35+
"Iteration scope for InteriorScopeHandler",
36+
);
7937
}
8038

8139
*generateScopeCandidates(
@@ -84,11 +42,13 @@ export class InteriorScopeHandler extends BaseScopeHandler {
8442
direction: Direction,
8543
hints: ScopeIteratorRequirements,
8644
): Iterable<TargetScope> {
87-
if (this.scopeHandler == null) {
45+
const scopeHandler = this.getScopeHandler();
46+
47+
if (scopeHandler == null) {
8848
return;
8949
}
9050

91-
const scopes = this.scopeHandler.generateScopes(
51+
const scopes = scopeHandler.generateScopes(
9252
editor,
9353
position,
9454
direction,
@@ -112,4 +72,47 @@ export class InteriorScopeHandler extends BaseScopeHandler {
11272
}
11373
}
11474
}
75+
76+
private getScopeHandler(): ScopeHandler | undefined {
77+
const languageScopeHandler = this.languageDefinitions
78+
.get(this.languageId)
79+
?.getScopeHandler(this.scopeType);
80+
81+
// If the scope type is explicit (ie, the user has specified a scope
82+
// type), then we don't want to include matching pairs. The user might
83+
// have said something like "inside element" and then we don't want to
84+
// yield the interior of the `<div>` pair.
85+
if (this.scopeType.explicitScopeType) {
86+
if (languageScopeHandler == null) {
87+
return undefined;
88+
}
89+
return languageScopeHandler;
90+
}
91+
92+
const pairInteriorScopeHandler = this.scopeHandlerFactory.create(
93+
{
94+
type: "surroundingPairInterior",
95+
delimiter: "any",
96+
allowWeakContainment: true,
97+
},
98+
this.languageId,
99+
);
100+
101+
if (languageScopeHandler == null) {
102+
return pairInteriorScopeHandler;
103+
}
104+
105+
return OneOfScopeHandler.createFromScopeHandlers(
106+
this.scopeHandlerFactory,
107+
{
108+
type: "oneOf",
109+
scopeTypes: [
110+
languageScopeHandler.scopeType,
111+
pairInteriorScopeHandler.scopeType!,
112+
],
113+
},
114+
[languageScopeHandler, pairInteriorScopeHandler],
115+
this.languageId,
116+
);
117+
}
115118
}

0 commit comments

Comments
 (0)