on master help sign in
Ensure non empty grouped nodes in textobject queries
commite83cdf3fd33a43e1ff78793995adbe23bd62ae49 authorGokul Soumya <gokulps15@gmail.com> dateSat 26 Feb 2022, 20:14 (5 years ago) parente6c36e8
1 file changed+7−1
helix-core/src/syntax.rs+7−1
helix-core/src/syntax.rs+7−1
@@ -246,6 +246,7 @@ pub struct TextObjectQuery {
246246
247247pub enum CapturedNode<'a> {
248248 Single(Node<'a>),
249+ /// Guarenteed to be not empty
249250 Grouped(Vec<Node<'a>>),
250251}
251252
@@ -318,7 +319,12 @@ impl TextObjectQuery {
318319
319320 let iter: Box<dyn Iterator<Item = CapturedNode>> = match quantifier {
320321 CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => {
321− Box::new(std::iter::once(CapturedNode::Grouped(nodes.collect())))
322+ let nodes: Vec<Node> = nodes.collect();
323+ if nodes.is_empty() {
324+ Box::new(std::iter::empty())
325+ } else {
326+ Box::new(std::iter::once(CapturedNode::Grouped(nodes)))
327+ }
322328 }
323329 _ => Box::new(nodes.map(CapturedNode::Single)),
324330 };