diff --git a/ratatui-core/src/text/text.rs b/ratatui-core/src/text/text.rs index 029545e0..f04981e1 100644 --- a/ratatui-core/src/text/text.rs +++ b/ratatui-core/src/text/text.rs @@ -665,6 +665,15 @@ impl core::ops::Add for Text<'_> { } } +/// Adds two `Text` together. +/// +/// This ignores the style and alignment of the second `Text`. +impl core::ops::AddAssign for Text<'_> { + fn add_assign(&mut self, rhs: Self) { + self.lines.extend(rhs.lines); + } +} + impl<'a> core::ops::AddAssign> for Text<'a> { fn add_assign(&mut self, line: Line<'a>) { self.push_line(line); @@ -940,6 +949,20 @@ mod tests { ); } + #[test] + fn add_assign_text() { + let mut text = Text::raw("Red").red(); + text += Text::raw("Blue").blue(); + assert_eq!( + text, + Text { + lines: vec![Line::raw("Red"), Line::raw("Blue")], + style: Style::new().red(), + alignment: None, + } + ); + } + #[test] fn add_assign_line() { let mut text = Text::raw("Red").red();