From e1b1a5ebc01311ff1ef34e205015570a2856481d Mon Sep 17 00:00:00 2001 From: Triton171 Date: Sat, 25 Jun 2022 20:12:30 +0200 Subject: [PATCH] Fix edge-case in tree-sitter expand_selection selection command (#2877) Co-authored-by: Triton171 --- helix-core/src/object.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs index b06f41444..d2d4fe70a 100644 --- a/helix-core/src/object.rs +++ b/helix-core/src/object.rs @@ -2,12 +2,11 @@ use crate::{Range, RopeSlice, Selection, Syntax}; use tree_sitter::Node; pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection { - select_node_impl(syntax, text, selection, |descendant, from, to| { - if descendant.start_byte() == from && descendant.end_byte() == to { - descendant.parent() - } else { - Some(descendant) + select_node_impl(syntax, text, selection, |mut node, from, to| { + while node.start_byte() == from && node.end_byte() == to { + node = node.parent()?; } + Some(node) }) }