From e83cdf3fd33a43e1ff78793995adbe23bd62ae49 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 26 Feb 2022 20:14:43 +0530 Subject: Ensure non empty grouped nodes in textobject queries --- helix-core/src/syntax.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'helix-core/src') 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>), } @@ -318,7 +319,12 @@ impl TextObjectQuery { let iter: Box> = match quantifier { CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => { - Box::new(std::iter::once(CapturedNode::Grouped(nodes.collect()))) + let nodes: Vec = 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)), }; -- cgit v1.2.3-70-g09d2