Fix edge-case in tree-sitter expand_selection selection command (#2877)

Co-authored-by: Triton171 <triton0171@gmail.com>
This commit is contained in:
Triton171 2022-06-25 20:12:30 +02:00 committed by GitHub
parent 18435899b2
commit e1b1a5ebc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,12 +2,11 @@ use crate::{Range, RopeSlice, Selection, Syntax};
use tree_sitter::Node; use tree_sitter::Node;
pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection { pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
select_node_impl(syntax, text, selection, |descendant, from, to| { select_node_impl(syntax, text, selection, |mut node, from, to| {
if descendant.start_byte() == from && descendant.end_byte() == to { while node.start_byte() == from && node.end_byte() == to {
descendant.parent() node = node.parent()?;
} else {
Some(descendant)
} }
Some(node)
}) })
} }