on master help sign in
Fix edge-case in tree-sitter expand_selection selection command (#2877)

Co-authored-by: Triton171 <triton0171@gmail.com>

commite1b1a5ebc01311ff1ef34e205015570a2856481d authorTriton171 <daniel.ebert@protonmail.com> dateSat 25 Jun 2022, 20:12 (4 years ago) parent1843589
1 file changed+4−5
helix-core/src/object.rs+4−5
helix-core/src/object.rs+4−5
@@ -2,12 +2,11 @@ use crate::{Range, RopeSlice, Selection, Syntax};
22use tree_sitter::Node;
33
44pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
5− select_node_impl(syntax, text, selection, |descendant, from, to| {
6− if descendant.start_byte() == from && descendant.end_byte() == to {
7− descendant.parent()
8− } else {
9− Some(descendant)
5+ select_node_impl(syntax, text, selection, |mut node, from, to| {
6+ while node.start_byte() == from && node.end_byte() == to {
7+ node = node.parent()?;
108 }
9+ Some(node)
1110 })
1211}
1312