summaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorTriton1712022-06-25 18:12:30 +0000
committerGitHub2022-06-25 18:12:30 +0000
commite1b1a5ebc01311ff1ef34e205015570a2856481d (patch)
tree8f1c1b7c08a82355e687bfea50ced44589ae9ea0 /helix-core/src
parent18435899b2310f5605153acfb7108e01f70caa79 (diff)
Fix edge-case in tree-sitter expand_selection selection command (#2877)
Co-authored-by: Triton171 <triton0171@gmail.com>
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/object.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs
index b06f4144..d2d4fe70 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)
})
}