Fix tooltip for figure reference (#6580)

This commit is contained in:
Laurenz 2025-07-09 15:50:54 +02:00 committed by GitHub
parent 3aa7e861e7
commit ac77fdbb6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@ use comemo::Track;
use ecow::{eco_vec, EcoString, EcoVec};
use typst::foundations::{Label, Styles, Value};
use typst::layout::PagedDocument;
use typst::model::BibliographyElem;
use typst::model::{BibliographyElem, FigureElem};
use typst::syntax::{ast, LinkedNode, SyntaxKind};
use crate::IdeWorld;
@ -75,8 +75,13 @@ pub fn analyze_labels(
for elem in document.introspector.all() {
let Some(label) = elem.label() else { continue };
let details = elem
.get_by_name("caption")
.or_else(|_| elem.get_by_name("body"))
.to_packed::<FigureElem>()
.and_then(|figure| match figure.caption.as_option() {
Some(Some(caption)) => Some(caption.pack_ref()),
_ => None,
})
.unwrap_or(elem)
.get_by_name("body")
.ok()
.and_then(|field| match field {
Value::Content(content) => Some(content),

View File

@ -378,4 +378,9 @@ mod tests {
.with_source("other.typ", "#let f = (x) => 1");
test(&world, -4, Side::After).must_be_code("(..) => ..");
}
#[test]
fn test_tooltip_reference() {
test("#figure(caption: [Hi])[]<f> @f", -1, Side::Before).must_be_text("Hi");
}
}