Skip to content

Commit

Permalink
Don't select empty nodes in moveTo
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Oct 23, 2020
1 parent 640f3f3 commit 11f25a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/tree.ts
Expand Up @@ -879,14 +879,16 @@ export class TreeCursor {
/// it will enter nodes that start at `pos`.
moveTo(pos: number, side: -1 | 0 | 1 = 0) {
// Move up to a node that actually holds the position, if possible
while ((side < 1 ? this.from >= pos : this.from > pos) ||
while (this.from == this.to ||
(side < 1 ? this.from >= pos : this.from > pos) ||
(side > -1 ? this.to <= pos : this.to < pos))
if (!this.parent()) break

// Then scan down into child nodes as far as possible
for (;;) {
if (side < 0 ? !this.childBefore(pos) : !this.childAfter(pos)) break
if ((side < 1 ? this.from >= pos : this.from > pos) ||
if (this.from == this.to ||
(side < 1 ? this.from >= pos : this.from > pos) ||
(side > -1 ? this.to <= pos : this.to < pos)) {
this.parent()
break
Expand Down
2 changes: 1 addition & 1 deletion test/test-tree.ts
Expand Up @@ -2,7 +2,7 @@ import {Tree, NodeGroup, NodeType, SyntaxNode, NodeProp} from ".."
import ist from "ist"

let types = "T a b c Pa Br".split(" ")
.map((s, i) => new (NodeType as any)(s, /^[abc]$/.test(s) ? NodeProp.group.set({}, "atom") : {}, i))
.map((s, i) => new (NodeType as any)(s, /^[abc]$/.test(s) ? NodeProp.group.set({}, ["atom"]) : {}, i))
let repeat = new (NodeType as any)("", {}, types.length, 8)
types.push(repeat)
let group = new NodeGroup(types)
Expand Down

0 comments on commit 11f25a2

Please sign in to comment.