From 181c633fe55a2648ddfaa97e3d8c57e8663a81bf Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:09:33 -0300 Subject: [PATCH] improve tree search --- crates/typst-syntax/src/node.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs index 6af41eacb..2a97124d3 100644 --- a/crates/typst-syntax/src/node.rs +++ b/crates/typst-syntax/src/node.rs @@ -826,31 +826,18 @@ impl<'a> LinkedNode<'a> { pub fn prev_attached_decorator(&self) -> Option { let mut cursor = self.prev_sibling_inner()?; let mut newlines = cursor.capped_newlines(); - let mut at_previous_line = false; while newlines < 2 { if cursor.kind() == SyntaxKind::Decorator { - // Decorators are attached if they're in a consecutive - // previous line. return Some(cursor); } - if newlines == 1 { - if at_previous_line { - // No decorators at the previous line. - // Don't move onto the line before the previous, since then - // the decorator wouldn't be attached. - return None; - } else { - at_previous_line = true; - } - } - cursor = cursor.prev_sibling_inner()?; - newlines = cursor.capped_newlines(); + newlines += cursor.capped_newlines(); } - // Found a parbreak or something else with two or more newlines. - // Can't have an attached decorator there. + // Decorators are attached if they're in the previous line. + // If we counted at least two newlines, no decorators are attached to + // this node. None }