Skip to content

Commit

Permalink
Fix next/prev tree-sitter inconsistency (helix-editor#7332)
Browse files Browse the repository at this point in the history
* Fix next/prev tree-sitter inconsistency

Before there where different results going to next or previous due to
sorting not dealing with multiple captures that start/end at the same
pos. I chose to prefer longer matches.

* Revert unnecessary change
  • Loading branch information
A-Walrus authored and rozaliev committed Jun 13, 2023
1 parent eb12af7 commit 9f59c25
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions helix-core/src/movement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::iter;
use std::{cmp::Reverse, iter};

use ropey::iter::Chars;
use tree_sitter::{Node, QueryCursor};
Expand Down Expand Up @@ -527,10 +527,10 @@ pub fn goto_treesitter_object(
let node = match dir {
Direction::Forward => nodes
.filter(|n| n.start_byte() > byte_pos)
.min_by_key(|n| n.start_byte())?,
.min_by_key(|n| (n.start_byte(), Reverse(n.end_byte())))?,
Direction::Backward => nodes
.filter(|n| n.end_byte() < byte_pos)
.max_by_key(|n| n.end_byte())?,
.max_by_key(|n| (n.end_byte(), Reverse(n.start_byte())))?,
};

let len = slice.len_bytes();
Expand Down

0 comments on commit 9f59c25

Please sign in to comment.