on master help sign in
Fix edge-case in tree-sitter expand_selection selection command (#2877)
e1b1a5eTriton171
helix-core/src/object.rs+4−5
@@ -2,12 +2,11 @@ use crate::{Range, RopeSlice, Selection, Syntax};
2use tree_sitter::Node;
2use tree_sitter::Node;
3
3
4pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
4pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
5− select_node_impl(syntax, text, selection, |descendant, from, to| {
5+ select_node_impl(syntax, text, selection, |mut node, from, to| {
6− if descendant.start_byte() == from && descendant.end_byte() == to {
6+ while node.start_byte() == from && node.end_byte() == to {
7− descendant.parent()
7+ node = node.parent()?;
8− } else {
9− Some(descendant)
10 }
8 }
9+ Some(node)
11 })
10 })
12}
11}
13
12