Skip to content

Commit 47dbf97

Browse files
Use list in tree
1 parent e48da99 commit 47dbf97

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function createNodes<T extends { range: Range }>(
4040
const parent = parents[parents.length - 1];
4141

4242
if (parent != null) {
43-
parent.children.push(node);
43+
parent.children.items.push(node);
4444
} else {
4545
results.push(node);
4646
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import type { Range } from "@cursorless/common";
2+
import { RangeLookupList } from "./RangeLookupList";
23

34
export class RangeTreeNode<T extends { range: Range }> {
4-
children: RangeTreeNode<T>[] = [];
5+
children: RangeLookupList<RangeTreeNode<T>>;
56

6-
constructor(private item: T) {}
7+
constructor(private item: T) {
8+
this.children = new RangeLookupList([]);
9+
}
710

811
get range(): Range {
912
return this.item.range;
1013
}
1114

12-
getSmallLestContaining(separator: Range): T {
13-
for (const child of this.children) {
14-
if (child.item.range.contains(separator)) {
15-
return child.getSmallLestContaining(separator);
16-
}
15+
getSmallLestContaining(range: Range): T {
16+
const child = this.children.getContaining(range);
17+
18+
if (child != null) {
19+
return child.getSmallLestContaining(range);
1720
}
1821

1922
return this.item;

0 commit comments

Comments
 (0)