diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-08 15:31:15 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-08 16:37:07 +0100 |
| commit | 12a59963b08b68cc39dcded4d3d3e6a6631c2732 (patch) | |
| tree | 3d20b014ada1ac06d2e74611a1798d7fb18dca33 /src/model/styles.rs | |
| parent | a7a4cae2948176119e8995bd8e1868f2d0e65029 (diff) | |
Reduce style chain bloat
Diffstat (limited to 'src/model/styles.rs')
| -rw-r--r-- | src/model/styles.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/model/styles.rs b/src/model/styles.rs index 8e731942..62e3188f 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -85,6 +85,15 @@ impl StyleMap { /// Like [`chain`](Self::chain) or [`apply_map`](Self::apply_map), but with /// only a entry. pub fn apply(&mut self, entry: StyleEntry) { + if let StyleEntry::Guard(a) = &entry { + if let [StyleEntry::Unguard(b), ..] = self.0.as_slice() { + if a == b { + self.0.remove(0); + return; + } + } + } + self.0.insert(0, entry); } @@ -124,7 +133,7 @@ impl From<StyleEntry> for StyleMap { impl Debug for StyleMap { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - for entry in self.0.iter().rev() { + for entry in self.0.iter() { writeln!(f, "{:?}", entry)?; } Ok(()) @@ -351,7 +360,7 @@ impl<'a> StyleChain<'a> { impl Debug for StyleChain<'_> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - for entry in self.entries() { + for entry in self.entries().collect::<Vec<_>>().into_iter().rev() { writeln!(f, "{:?}", entry)?; } Ok(()) |
