summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-07-19 13:11:54 +0200
committerLaurenz <laurmaedje@gmail.com>2023-07-19 13:11:54 +0200
commitfc90b72355db92d9814de0f0254d354dc7a66573 (patch)
treeb298659fabe035537c7783a83abf8c8e5497c287 /crates
parentfa9e2c62379792c045288d1ab66f68c5a2e18c42 (diff)
Identify state by key only
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/meta/counter.rs17
-rw-r--r--crates/typst-library/src/meta/state.rs8
2 files changed, 15 insertions, 10 deletions
diff --git a/crates/typst-library/src/meta/counter.rs b/crates/typst-library/src/meta/counter.rs
index 9a223b32..ca4f3bc5 100644
--- a/crates/typst-library/src/meta/counter.rs
+++ b/crates/typst-library/src/meta/counter.rs
@@ -385,7 +385,7 @@ impl Counter {
/// Produce content that performs a state update.
pub fn update(self, update: CounterUpdate) -> Content {
- UpdateElem::new(self, update).pack()
+ UpdateElem::new(self.0, update).pack()
}
/// Produce the whole sequence of counter states.
@@ -461,7 +461,7 @@ impl Counter {
/// The selector relevant for this counter's updates.
fn selector(&self) -> Selector {
let mut selector =
- Selector::Elem(UpdateElem::func(), Some(dict! { "counter" => self.clone() }));
+ Selector::Elem(UpdateElem::func(), Some(dict! { "key" => self.0.clone() }));
if let CounterKey::Selector(key) = &self.0 {
selector = Selector::Or(eco_vec![selector, key.clone()]);
@@ -502,8 +502,13 @@ pub enum CounterKey {
cast! {
CounterKey,
+ self => match self {
+ Self::Page => PageElem::func().into_value(),
+ Self::Selector(v) => v.into_value(),
+ Self::Str(v) => v.into_value(),
+ },
v: Str => Self::Str(v),
- label: Label => Self::Selector(Selector::Label(label)),
+ v: Label => Self::Selector(Selector::Label(v)),
v: ElemFunc => {
if v == PageElem::func() {
Self::Page
@@ -511,7 +516,7 @@ cast! {
Self::Selector(LocatableSelector::from_value(v.into_value())?.0)
}
},
- selector: LocatableSelector => Self::Selector(selector.0),
+ v: LocatableSelector => Self::Selector(v.0),
}
impl Debug for CounterKey {
@@ -666,9 +671,9 @@ impl Show for DisplayElem {
/// Category: special
#[element(Locatable, Show)]
struct UpdateElem {
- /// The counter.
+ /// The key that identifies the counter.
#[required]
- counter: Counter,
+ key: CounterKey,
/// The update to perform on the counter.
#[required]
diff --git a/crates/typst-library/src/meta/state.rs b/crates/typst-library/src/meta/state.rs
index aee53a29..5b304972 100644
--- a/crates/typst-library/src/meta/state.rs
+++ b/crates/typst-library/src/meta/state.rs
@@ -297,7 +297,7 @@ impl State {
/// Produce content that performs a state update.
pub fn update(self, update: StateUpdate) -> Content {
- UpdateElem::new(self, update).pack()
+ UpdateElem::new(self.key, update).pack()
}
/// Produce the whole sequence of states.
@@ -349,7 +349,7 @@ impl State {
/// The selector for this state's updates.
fn selector(&self) -> Selector {
- Selector::Elem(UpdateElem::func(), Some(dict! { "state" => self.clone() }))
+ Selector::Elem(UpdateElem::func(), Some(dict! { "key" => self.key.clone() }))
}
}
@@ -423,9 +423,9 @@ impl Show for DisplayElem {
/// Category: special
#[element(Locatable, Show)]
struct UpdateElem {
- /// The state.
+ /// The key that identifies the state.
#[required]
- state: State,
+ key: Str,
/// The update to perform on the state.
#[required]