diff --git a/examples/rich-text/src/main.rs b/examples/rich-text/src/main.rs index 66092db..a3d8c41 100644 --- a/examples/rich-text/src/main.rs +++ b/examples/rich-text/src/main.rs @@ -119,7 +119,7 @@ fn main() { editor .buffer_mut() - .set_rich_text(spans.iter().copied(), Shaping::Advanced); + .set_rich_text(spans.iter().copied(), attrs, Shaping::Advanced); let mut swash_cache = SwashCache::new(); diff --git a/src/buffer.rs b/src/buffer.rs index a04675d..3a32373 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -618,7 +618,7 @@ impl Buffer { attrs: Attrs, shaping: Shaping, ) { - self.set_rich_text(font_system, [(text, attrs)], shaping); + self.set_rich_text(font_system, [(text, attrs)], attrs, shaping); } /// Set text of buffer, using an iterator of styled spans (pairs of text and attributes) @@ -634,6 +634,7 @@ impl Buffer { /// ("hello, ", attrs), /// ("cosmic\ntext", attrs.family(Family::Monospace)), /// ], + /// attrs, /// Shaping::Advanced, /// ); /// ``` @@ -641,13 +642,14 @@ impl Buffer { &mut self, font_system: &mut FontSystem, spans: I, + default_attrs: Attrs, shaping: Shaping, ) where I: IntoIterator)>, { self.lines.clear(); - let mut attrs_list = AttrsList::new(Attrs::new()); + let mut attrs_list = AttrsList::new(default_attrs); let mut line_string = String::new(); let mut end = 0; let (string, spans_data): (String, Vec<_>) = spans @@ -676,7 +678,7 @@ impl Buffer { // this is reached only if this text is empty self.lines.push(BufferLine::new( String::new(), - AttrsList::new(Attrs::new()), + AttrsList::new(default_attrs), shaping, )); break; @@ -705,7 +707,7 @@ impl Buffer { if maybe_line.is_some() { // finalize this line and start a new line let prev_attrs_list = - core::mem::replace(&mut attrs_list, AttrsList::new(Attrs::new())); + core::mem::replace(&mut attrs_list, AttrsList::new(default_attrs)); let prev_line_string = core::mem::take(&mut line_string); let buffer_line = BufferLine::new(prev_line_string, prev_attrs_list, shaping); self.lines.push(buffer_line); @@ -941,14 +943,16 @@ impl<'a> BorrowedWithFontSystem<'a, Buffer> { /// ("hello, ", attrs), /// ("cosmic\ntext", attrs.family(Family::Monospace)), /// ], + /// attrs, /// Shaping::Advanced, /// ); /// ``` - pub fn set_rich_text<'r, 's, I>(&mut self, spans: I, shaping: Shaping) + pub fn set_rich_text<'r, 's, I>(&mut self, spans: I, default_attrs: Attrs, shaping: Shaping) where I: IntoIterator)>, { - self.inner.set_rich_text(self.font_system, spans, shaping); + self.inner + .set_rich_text(self.font_system, spans, default_attrs, shaping); } /// Draw the buffer