aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGokul Soumya2022-02-26 14:44:43 +0000
committerBlaž Hrastnik2022-03-01 01:32:50 +0000
commite83cdf3fd33a43e1ff78793995adbe23bd62ae49 (patch)
tree9cdb1e744920e7e4fb58d474537a6054a0956abb
parente6c36e82cf0a5d609e22bb1d9ee267de8854007b (diff)
Ensure non empty grouped nodes in textobject queries
-rw-r--r--helix-core/src/syntax.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 8f62bead..f2939e3d 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -246,6 +246,7 @@ pub struct TextObjectQuery {
pub enum CapturedNode<'a> {
Single(Node<'a>),
+ /// Guarenteed to be not empty
Grouped(Vec<Node<'a>>),
}
@@ -318,7 +319,12 @@ impl TextObjectQuery {
let iter: Box<dyn Iterator<Item = CapturedNode>> = match quantifier {
CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => {
- Box::new(std::iter::once(CapturedNode::Grouped(nodes.collect())))
+ let nodes: Vec<Node> = nodes.collect();
+ if nodes.is_empty() {
+ Box::new(std::iter::empty())
+ } else {
+ Box::new(std::iter::once(CapturedNode::Grouped(nodes)))
+ }
}
_ => Box::new(nodes.map(CapturedNode::Single)),
};