summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src/span.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-10 13:59:00 +0200
committerGitHub <noreply@github.com>2024-10-10 11:59:00 +0000
commit6257e4d6cf060f367c3f2eb2d005a091b6432e88 (patch)
tree9ae46a48c3b3d4c90d3cfc9da77df5951e942fa4 /crates/typst-syntax/src/span.rs
parent9ee80762a55c0d173664d9ac33cb762b79341a96 (diff)
More robust glyph drawing (#5159)
Diffstat (limited to 'crates/typst-syntax/src/span.rs')
-rw-r--r--crates/typst-syntax/src/span.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs
index 4d5dd9c3..85745f60 100644
--- a/crates/typst-syntax/src/span.rs
+++ b/crates/typst-syntax/src/span.rs
@@ -92,6 +92,13 @@ impl Span {
}
}
+ /// Find the first non-detached span in the iterator.
+ pub fn find(iter: impl IntoIterator<Item = Self>) -> Self {
+ iter.into_iter()
+ .find(|span| !span.is_detached())
+ .unwrap_or(Span::detached())
+ }
+
/// Resolve a file location relative to this span's source.
pub fn resolve_path(self, path: &str) -> Result<FileId, EcoString> {
let Some(file) = self.id() else {