From 241c4ca357b91334c07cb41e2679857841b33e19 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 2 Nov 2023 10:24:21 -0600 Subject: [PATCH] Buffer::set_rich_text: Only add attrs if they don't match the defaults --- src/buffer.rs | 5 ++++- src/edit/syntect.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 2f60395..9d23f63 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -704,7 +704,10 @@ impl Buffer { let text_start = line_string.len(); line_string.push_str(text); let text_end = line_string.len(); - attrs_list.add_span(text_start..text_end, *attrs); + // Only add attrs if they don't match the defaults + if *attrs != attrs_list.defaults() { + attrs_list.add_span(text_start..text_end, *attrs); + } } // we know that at the end of a line, diff --git a/src/edit/syntect.rs b/src/edit/syntect.rs index 5d995ac..be5e5b2 100644 --- a/src/edit/syntect.rs +++ b/src/edit/syntect.rs @@ -188,7 +188,7 @@ impl<'a> Edit for SyntaxEditor<'a> { match buffer.line_layout(font_system, line_i) { Some(layout_lines) => { total_layout += layout_lines.len() as i32; - }, + } None => { //TODO: should this be possible? } @@ -251,7 +251,7 @@ impl<'a> Edit for SyntaxEditor<'a> { match buffer.line_layout(font_system, line_i) { Some(layout_lines) => { total_layout += layout_lines.len() as i32; - }, + } None => { //TODO: should this be possible? }