summaryrefslogtreecommitdiff
path: root/library/src/text
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-22 20:12:37 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-22 20:12:37 +0100
commit5992f11b4c33d82fa245205980094accb57a8c76 (patch)
treeb0043ba4b4cabab2fa8f63ec80f37c9d247e134a /library/src/text
parentb476de87b7cea1405bf3c051ff8e0ac7c473dbae (diff)
Reorganize content type
Diffstat (limited to 'library/src/text')
-rw-r--r--library/src/text/par.rs16
-rw-r--r--library/src/text/shift.rs8
2 files changed, 11 insertions, 13 deletions
diff --git a/library/src/text/par.rs b/library/src/text/par.rs
index 37d5e396..196878f8 100644
--- a/library/src/text/par.rs
+++ b/library/src/text/par.rs
@@ -420,7 +420,7 @@ fn collect<'a>(
let segment = if child.is::<SpaceNode>() {
full.push(' ');
Segment::Text(1)
- } else if let Some(node) = child.downcast::<TextNode>() {
+ } else if let Some(node) = child.to::<TextNode>() {
let prev = full.len();
if let Some(case) = styles.get(TextNode::CASE) {
full.push_str(&case.apply(&node.0));
@@ -428,18 +428,18 @@ fn collect<'a>(
full.push_str(&node.0);
}
Segment::Text(full.len() - prev)
- } else if let Some(node) = child.downcast::<LinebreakNode>() {
+ } else if let Some(node) = child.to::<LinebreakNode>() {
let c = if node.justify { '\u{2028}' } else { '\n' };
full.push(c);
Segment::Text(c.len_utf8())
- } else if let Some(node) = child.downcast::<SmartQuoteNode>() {
+ } else if let Some(node) = child.to::<SmartQuoteNode>() {
let prev = full.len();
if styles.get(TextNode::SMART_QUOTES) {
let lang = styles.get(TextNode::LANG);
let region = styles.get(TextNode::REGION);
let quotes = Quotes::from_lang(lang, region);
let peeked = iter.peek().and_then(|(child, _)| {
- if let Some(node) = child.downcast::<TextNode>() {
+ if let Some(node) = child.to::<TextNode>() {
node.0.chars().next()
} else if child.is::<SmartQuoteNode>() {
Some('"')
@@ -455,7 +455,7 @@ fn collect<'a>(
full.push(if node.double { '"' } else { '\'' });
}
Segment::Text(full.len() - prev)
- } else if let Some(&node) = child.downcast::<HNode>() {
+ } else if let Some(&node) = child.to::<HNode>() {
full.push(SPACING_REPLACE);
Segment::Spacing(node.amount)
} else if child.has::<dyn LayoutInline>() {
@@ -523,7 +523,7 @@ fn prepare<'a>(
}
},
Segment::Inline(inline) => {
- if let Some(repeat) = inline.downcast::<RepeatNode>() {
+ if let Some(repeat) = inline.to::<RepeatNode>() {
items.push(Item::Repeat(repeat, styles));
} else {
let size = Size::new(regions.first.x, regions.base.y);
@@ -606,11 +606,11 @@ fn is_compatible(a: Script, b: Script) -> bool {
/// Get a style property, but only if it is the same for all children of the
/// paragraph.
-fn shared_get<'a, K: Key<'a>>(
+fn shared_get<'a, K: Key>(
styles: StyleChain<'a>,
children: &StyleVec<Content>,
key: K,
-) -> Option<K::Output> {
+) -> Option<K::Output<'a>> {
children
.styles()
.all(|map| !map.contains(key))
diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs
index 32f110c6..e63211c6 100644
--- a/library/src/text/shift.rs
+++ b/library/src/text/shift.rs
@@ -69,13 +69,11 @@ impl<const S: ShiftKind> Show for ShiftNode<S> {
/// Find and transform the text contained in `content` to the given script kind
/// if and only if it only consists of `Text`, `Space`, and `Empty` leaf nodes.
fn search_text(content: &Content, mode: ShiftKind) -> Option<EcoString> {
- if content.is_empty() {
- Some(EcoString::new())
- } else if content.is::<SpaceNode>() {
+ if content.is::<SpaceNode>() {
Some(' '.into())
- } else if let Some(text) = content.downcast::<TextNode>() {
+ } else if let Some(text) = content.to::<TextNode>() {
convert_script(&text.0, mode)
- } else if let Some(seq) = content.downcast::<SequenceNode>() {
+ } else if let Some(seq) = content.to::<SequenceNode>() {
let mut full = EcoString::new();
for item in seq.0.iter() {
match search_text(item, mode) {