mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Merge f06e591144d2c1093e9cc21b545bbea30708b6c5 into 9b09146a6b5e936966ed7ee73bce9dd2df3810ae
This commit is contained in:
commit
3ae2a362f4
@ -62,7 +62,7 @@ fn eval_markup<'a>(
|
||||
));
|
||||
}
|
||||
|
||||
*elem = std::mem::take(elem).labelled(label);
|
||||
*elem = std::mem::take(elem).labelled(label, expr.span());
|
||||
} else {
|
||||
vm.engine.sink.warn(warning!(
|
||||
expr.span(),
|
||||
|
@ -75,7 +75,10 @@ pub fn definition(
|
||||
let label = Label::new(PicoStr::intern(node.cast::<ast::Ref>()?.target()));
|
||||
let selector = Selector::Label(label);
|
||||
let elem = document?.introspector.query_first(&selector)?;
|
||||
return Some(Definition::Span(elem.span()));
|
||||
let labelled_at = elem.labelled_at().or(elem.span());
|
||||
if !labelled_at.is_detached() {
|
||||
return Some(Definition::Span(labelled_at));
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
@ -181,7 +184,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_definition_ref() {
|
||||
test("#figure[] <hi> See @hi", -2, Side::After).must_be_at("main.typ", 1..9);
|
||||
test("#figure[] <hi> See @hi", -2, Side::After).must_be_at("main.typ", 10..14);
|
||||
let source =
|
||||
r#"#let test1(body) = figure(body); #test1([Test1]) <fig:test1> @fig:test1"#;
|
||||
test(source, -2, Side::After).must_be_at("main.typ", 49..60);
|
||||
let source = r#"#let test1(body) = figure(body); #test1([Test1]) <fig:test1> @fig:test1
|
||||
#let test2(body) = test1(body); #test2([Test2]) <fig:test2>; @fig:test2"#;
|
||||
test(source, -2, Side::After).must_be_at("main.typ", 120..131);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -82,6 +82,8 @@ pub struct Content {
|
||||
struct Inner<T: ?Sized + 'static> {
|
||||
/// An optional label attached to the element.
|
||||
label: Option<Label>,
|
||||
/// The span where the label is attached.
|
||||
labelled_at: Span,
|
||||
/// The element's location which identifies it in the layouted output.
|
||||
location: Option<Location>,
|
||||
/// Manages the element during realization.
|
||||
@ -99,6 +101,7 @@ impl Content {
|
||||
Self {
|
||||
inner: Arc::new(Inner {
|
||||
label: None,
|
||||
labelled_at: Span::detached(),
|
||||
location: None,
|
||||
lifecycle: SmallBitSet::new(),
|
||||
elem: elem.into(),
|
||||
@ -135,9 +138,16 @@ impl Content {
|
||||
self.inner.label
|
||||
}
|
||||
|
||||
/// Get the span where the label is attached.
|
||||
pub fn labelled_at(&self) -> Span {
|
||||
self.inner.labelled_at
|
||||
}
|
||||
|
||||
/// Attach a label to the content.
|
||||
pub fn labelled(mut self, label: Label) -> Self {
|
||||
self.set_label(label);
|
||||
pub fn labelled(mut self, label: Label, labelled_at: Span) -> Self {
|
||||
let m = self.make_mut();
|
||||
m.label = Some(label);
|
||||
m.labelled_at = labelled_at;
|
||||
self
|
||||
}
|
||||
|
||||
@ -540,8 +550,7 @@ impl Content {
|
||||
/// The content's element function. This function can be used to create the element
|
||||
/// contained in this content. It can be used in set and show rules for the
|
||||
/// element. Can be compared with global functions to check whether you have
|
||||
/// a specific
|
||||
/// kind of element.
|
||||
/// a specific kind of element.
|
||||
#[func]
|
||||
pub fn func(&self) -> Element {
|
||||
self.elem()
|
||||
@ -742,6 +751,7 @@ impl<T: NativeElement> Bounds for T {
|
||||
location: inner.location,
|
||||
lifecycle: inner.lifecycle.clone(),
|
||||
elem: LazyHash::reuse(self.clone(), &inner.elem),
|
||||
labelled_at: inner.labelled_at,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user