Skip to content

Commit

Permalink
Ensure non empty grouped nodes in textobject queries
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin authored and archseer committed Mar 1, 2022
1 parent e6c36e8 commit e83cdf3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub struct TextObjectQuery {

pub enum CapturedNode<'a> {
Single(Node<'a>),
/// Guarenteed to be not empty
Grouped(Vec<Node<'a>>),
}

Expand Down Expand Up @@ -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)),
};
Expand Down

0 comments on commit e83cdf3

Please sign in to comment.