mirror of
https://github.com/typst/typst
synced 2025-05-21 20:45:27 +08:00
rename .contains to .within
This commit is contained in:
parent
d97039c50b
commit
5fb96b28b4
@ -93,8 +93,8 @@ pub enum Selector {
|
|||||||
Before { selector: Arc<Self>, end: Arc<Self>, inclusive: bool },
|
Before { selector: Arc<Self>, end: Arc<Self>, inclusive: bool },
|
||||||
/// Matches all matches of `selector` after `start`.
|
/// Matches all matches of `selector` after `start`.
|
||||||
After { selector: Arc<Self>, start: Arc<Self>, inclusive: bool },
|
After { selector: Arc<Self>, start: Arc<Self>, inclusive: bool },
|
||||||
/// Matches all children of `selector` matching `children_selector`
|
/// Matches all children of `ancestor` matching `selector`
|
||||||
Contains { selector: Arc<Self>, children_selector: Arc<Self> },
|
Within { selector: Arc<Self>, ancestor: Arc<Self> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selector {
|
impl Selector {
|
||||||
@ -144,7 +144,7 @@ impl Selector {
|
|||||||
Self::Regex(_)
|
Self::Regex(_)
|
||||||
| Self::Before { .. }
|
| Self::Before { .. }
|
||||||
| Self::After { .. }
|
| Self::After { .. }
|
||||||
| Self::Contains { .. } => false,
|
| Self::Within { .. } => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,13 +227,12 @@ impl Selector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a modified selector that only matches children of what `self`
|
/// Returns a modified selector that only matches `self` if it is contained in an `ancestor`.
|
||||||
/// selects that match `children_selector`.
|
|
||||||
#[func]
|
#[func]
|
||||||
pub fn contains(self, children_selector: LocatableSelector) -> Selector {
|
pub fn within(self, ancestor: LocatableSelector) -> Selector {
|
||||||
Self::Contains {
|
Self::Within {
|
||||||
selector: Arc::new(self),
|
selector: Arc::new(self),
|
||||||
children_selector: Arc::new(children_selector.0),
|
ancestor: Arc::new(ancestor.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,7 +280,7 @@ impl Repr for Selector {
|
|||||||
inclusive_arg
|
inclusive_arg
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::Contains { selector, children_selector } => {
|
Self::Within { selector, ancestor: children_selector } => {
|
||||||
eco_format!("{}.contains({})", selector.repr(), children_selector.repr())
|
eco_format!("{}.contains({})", selector.repr(), children_selector.repr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,7 +370,7 @@ impl FromValue for LocatableSelector {
|
|||||||
}
|
}
|
||||||
Selector::Before { selector, end: split, .. }
|
Selector::Before { selector, end: split, .. }
|
||||||
| Selector::After { selector, start: split, .. }
|
| Selector::After { selector, start: split, .. }
|
||||||
| Selector::Contains { selector, children_selector: split } => {
|
| Selector::Within { selector, ancestor: split } => {
|
||||||
for selector in [selector, split] {
|
for selector in [selector, split] {
|
||||||
validate(selector)?;
|
validate(selector)?;
|
||||||
}
|
}
|
||||||
@ -451,7 +450,7 @@ impl FromValue for ShowableSelector {
|
|||||||
| Selector::Can(_)
|
| Selector::Can(_)
|
||||||
| Selector::Before { .. }
|
| Selector::Before { .. }
|
||||||
| Selector::After { .. }
|
| Selector::After { .. }
|
||||||
| Selector::Contains { .. } => {
|
| Selector::Within { .. } => {
|
||||||
bail!("this selector cannot be used with show")
|
bail!("this selector cannot be used with show")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,10 +185,10 @@ impl Introspector {
|
|||||||
}
|
}
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
Selector::Contains { selector, children_selector } => self
|
Selector::Within { selector, ancestor } => self
|
||||||
.query(selector)
|
.query(ancestor)
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|children| children.query(children_selector))
|
.flat_map(|children| children.query(selector))
|
||||||
.collect(),
|
.collect(),
|
||||||
// Not supported here.
|
// Not supported here.
|
||||||
Selector::Can(_) | Selector::Regex(_) => EcoVec::new(),
|
Selector::Can(_) | Selector::Regex(_) => EcoVec::new(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user