From bbc1370dd578a090836e34cf936c6d7b32bf5a07 Mon Sep 17 00:00:00 2001 From: "Jeong, Hun" Date: Sun, 7 Apr 2024 09:29:58 -0700 Subject: [PATCH] feat(lib)!: treat nodes' end ranges exclusively in `goto_first_child_for_{byte,point}` This goes back on #1640, because now cursors are bi-directional, and going to the previous sibling is simple. --- cli/src/tests/tree_test.rs | 7 ++++--- lib/src/tree_cursor.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/src/tests/tree_test.rs b/cli/src/tests/tree_test.rs index 6ba47a03..90898a0c 100644 --- a/cli/src/tests/tree_test.rs +++ b/cli/src/tests/tree_test.rs @@ -475,12 +475,13 @@ fn test_tree_cursor_child_for_point() { assert_eq!(c.node().kind(), "program"); // descend to expression statement - assert_eq!(c.goto_first_child_for_point(Point::new(6, 6)), Some(0)); + assert_eq!(c.goto_first_child_for_point(Point::new(6, 5)), Some(0)); assert_eq!(c.node().kind(), "expression_statement"); // step into ';' and back up assert_eq!(c.goto_first_child_for_point(Point::new(7, 0)), None); - assert_eq!(c.goto_first_child_for_point(Point::new(6, 6)), Some(1)); + assert_eq!(c.goto_first_child_for_point(Point::new(6, 6)), None); + assert_eq!(c.goto_first_child_for_point(Point::new(6, 5)), Some(1)); assert_eq!( (c.node().kind(), c.node().start_position()), (";", Point::new(6, 5)) @@ -517,7 +518,7 @@ fn test_tree_cursor_child_for_point() { assert!(c.goto_parent()); // step into first ',' and back up - assert_eq!(c.goto_first_child_for_point(Point::new(1, 12)), Some(2)); + assert_eq!(c.goto_first_child_for_point(Point::new(1, 11)), Some(2)); assert_eq!( (c.node().kind(), c.node().start_position()), (",", Point::new(1, 11)) diff --git a/lib/src/tree_cursor.c b/lib/src/tree_cursor.c index 24416663..250b42da 100644 --- a/lib/src/tree_cursor.c +++ b/lib/src/tree_cursor.c @@ -274,7 +274,7 @@ static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point( CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); while (ts_tree_cursor_child_iterator_next(&iterator, &entry, &visible)) { Length entry_end = length_add(entry.position, ts_subtree_size(*entry.subtree)); - bool at_goal = entry_end.bytes >= goal_byte && point_gte(entry_end.extent, goal_point); + bool at_goal = entry_end.bytes > goal_byte && point_gt(entry_end.extent, goal_point); uint32_t visible_child_count = ts_subtree_visible_child_count(*entry.subtree); if (at_goal) { if (visible) {