select smaller range on some case

This commit is contained in:
cossonleo 2021-10-28 13:31:44 +08:00 committed by Blaž Hrastnik
parent f1d339919f
commit befecc8a9a

View file

@ -13,8 +13,13 @@ pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: &Selection)
let parent = match tree
.root_node()
.descendant_for_byte_range(from, to)
.and_then(|node| node.parent())
{
.and_then(|node| {
if node.child_count() == 0 || (node.start_byte() == from && node.end_byte() == to) {
node.parent()
} else {
Some(node)
}
}) {
Some(parent) => parent,
None => return range,
};