mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
initial improvements to allow multiline annotations
- Improve tree search - Improve annotation argument loop
This commit is contained in:
parent
e105cd1956
commit
46e4fbfac7
@ -271,9 +271,9 @@ impl Lexer<'_> {
|
|||||||
// parenthesis) or newline. We have to check the newline before eating
|
// parenthesis) or newline. We have to check the newline before eating
|
||||||
// (through '.peek()') to ensure it is not considered part of the
|
// (through '.peek()') to ensure it is not considered part of the
|
||||||
// annotation.
|
// annotation.
|
||||||
let mut current_start = self.s.cursor();
|
|
||||||
let mut found_closing_paren = false;
|
let mut found_closing_paren = false;
|
||||||
while !self.s.at(is_newline) {
|
while !self.s.at(is_newline) {
|
||||||
|
let current_start = self.s.cursor();
|
||||||
let token = match self.s.eat() {
|
let token = match self.s.eat() {
|
||||||
Some(c) if c.is_whitespace() => {
|
Some(c) if c.is_whitespace() => {
|
||||||
self.s.eat_while(is_inline_whitespace);
|
self.s.eat_while(is_inline_whitespace);
|
||||||
@ -325,8 +325,6 @@ impl Lexer<'_> {
|
|||||||
|
|
||||||
let node = self.emit_token(token, current_start);
|
let node = self.emit_token(token, current_start);
|
||||||
subtree.push(node);
|
subtree.push(node);
|
||||||
|
|
||||||
current_start = self.s.cursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right parenthesis (covered above)
|
// Right parenthesis (covered above)
|
||||||
|
@ -825,19 +825,23 @@ impl<'a> LinkedNode<'a> {
|
|||||||
pub fn prev_attached_annotation(&self) -> Option<Self> {
|
pub fn prev_attached_annotation(&self) -> Option<Self> {
|
||||||
let mut cursor = self.prev_sibling_inner()?;
|
let mut cursor = self.prev_sibling_inner()?;
|
||||||
let mut newlines = cursor.capped_newlines();
|
let mut newlines = cursor.capped_newlines();
|
||||||
while newlines < 2 {
|
while cursor.kind() != SyntaxKind::Annotation {
|
||||||
if cursor.kind() == SyntaxKind::Annotation {
|
if newlines >= 2 {
|
||||||
return Some(cursor);
|
// Annotations are attached if they're in the previous line.
|
||||||
|
// If we counted at least two newlines without finding an
|
||||||
|
// annotation, no annotations are attached to this node.
|
||||||
|
//
|
||||||
|
// Note that this check is only run if the latest node was not
|
||||||
|
// an annotation, otherwise annotations with multiple lines
|
||||||
|
// would always be rejected.
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = cursor.prev_sibling_inner()?;
|
cursor = cursor.prev_sibling_inner()?;
|
||||||
newlines += cursor.capped_newlines();
|
newlines += cursor.capped_newlines();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotations are attached if they're in the previous line.
|
Some(cursor)
|
||||||
// If we counted at least two newlines, no annotations are attached to
|
|
||||||
// this node.
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the next non-trivia sibling node.
|
/// Get the next non-trivia sibling node.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user