-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathVscodeScopeTargetVisualizer.ts
More file actions
57 lines (50 loc) · 1.65 KB
/
VscodeScopeTargetVisualizer.ts
File metadata and controls
57 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type {
Disposable,
GeneralizedRange,
ScopeSupport,
TargetRanges,
TextEditor,
} from "@cursorless/lib-common";
import { toCharacterRange } from "@cursorless/lib-common";
import type { VscodeTextEditor } from "../VscodeTextEditor";
import { VscodeScopeVisualizer } from "./VscodeScopeVisualizer";
abstract class VscodeScopeTargetVisualizer extends VscodeScopeVisualizer {
protected abstract getTargetRange(
targetRanges: TargetRanges,
): GeneralizedRange;
protected getScopeSupport(editor: TextEditor): ScopeSupport {
return this.scopeProvider.getScopeSupport(editor, this.scopeType);
}
protected registerListener(): Disposable {
return this.scopeProvider.onDidChangeScopeRanges(
(editor, scopeRanges) => {
this.renderer.setScopes(
editor as VscodeTextEditor,
scopeRanges.map(({ domain, targets }) => ({
domain: toCharacterRange(domain),
nestedRanges: targets.map((target) => this.getTargetRange(target)),
})),
);
},
{ scopeType: this.scopeType, visibleOnly: true },
);
}
}
export class VscodeScopeContentVisualizer extends VscodeScopeTargetVisualizer {
protected getTargetRange({ contentRange }: TargetRanges): GeneralizedRange {
return toCharacterRange(contentRange);
}
protected getNestedScopeRangeType() {
return "content" as const;
}
}
export class VscodeScopeRemovalVisualizer extends VscodeScopeTargetVisualizer {
protected getTargetRange({
removalHighlightRange,
}: TargetRanges): GeneralizedRange {
return removalHighlightRange;
}
protected getNestedScopeRangeType() {
return "removal" as const;
}
}