diff options
author | cossonleo | 2021-10-28 05:31:44 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-10-29 01:04:12 +0000 |
commit | befecc8a9a087436a9dbc6942e328646c3391874 (patch) | |
tree | 82b889100b4b57fc603e1103922689c52eb3ca8e /helix-core/src | |
parent | f1d339919f4299d570bb6f7fcf5fcc58c0f281cf (diff) |
select smaller range on some case
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/object.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs index d9558dd8..717c5994 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, }; |