From befecc8a9a087436a9dbc6942e328646c3391874 Mon Sep 17 00:00:00 2001 From: cossonleo Date: Thu, 28 Oct 2021 13:31:44 +0800 Subject: [PATCH] select smaller range on some case --- helix-core/src/object.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs index d9558dd83..717c59947 100644 --- a/helix-core/src/object.rs +++ b/helix-core/src/object.rs @@ -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, };