summaryrefslogtreecommitdiff
path: root/src/model/content.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-08 15:31:15 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-08 16:37:07 +0100
commit12a59963b08b68cc39dcded4d3d3e6a6631c2732 (patch)
tree3d20b014ada1ac06d2e74611a1798d7fb18dca33 /src/model/content.rs
parenta7a4cae2948176119e8995bd8e1868f2d0e65029 (diff)
Reduce style chain bloat
Diffstat (limited to 'src/model/content.rs')
-rw-r--r--src/model/content.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index bc25cd79..3851d38d 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -115,10 +115,14 @@ impl Content {
pub fn styled_with_entry(mut self, entry: StyleEntry) -> Self {
if let Some(styled) = self.try_downcast_mut::<StyledNode>() {
styled.map.apply(entry);
- return self;
+ self
+ } else if let Some(styled) = self.downcast::<StyledNode>() {
+ let mut map = styled.map.clone();
+ map.apply(entry);
+ StyledNode { sub: styled.sub.clone(), map }.pack()
+ } else {
+ StyledNode { sub: self, map: entry.into() }.pack()
}
-
- StyledNode { sub: self, map: entry.into() }.pack()
}
/// Style this content with a full style map.