From a0aec0b17657dc2747b559c1406e1fa30e4516ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 7 May 2025 10:25:00 +0200 Subject: [PATCH] room-history: Remove whitespaces before newlines in HTML messages --- .../room_history/message_row/text/inline_html.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/session/view/content/room_history/message_row/text/inline_html.rs b/src/session/view/content/room_history/message_row/text/inline_html.rs index 4044bd57..b27e9aef 100644 --- a/src/session/view/content/room_history/message_row/text/inline_html.rs +++ b/src/session/view/content/room_history/message_row/text/inline_html.rs @@ -205,6 +205,8 @@ impl<'a> InlineHtmlBuilder<'a> { if self.single_line { self.truncated = true; } else { + // Remove whitespaces before the newline. + self.inner.truncate_end_whitespaces(); self.inner.push('\n'); } } @@ -220,8 +222,12 @@ impl<'a> InlineHtmlBuilder<'a> { /// Append the given text node content. fn append_text_node(&mut self, text: &str, context: NodeContext) { - // Remove spaces at the beginning and end of an HTML element. - let text = text.collapse_whitespaces(context.is_first_child, context.is_last_child); + // Remove spaces at the beginning and end of an HTML element, and after a + // newline. + let text = text.collapse_whitespaces( + context.is_first_child || self.inner.ends_with('\n'), + context.is_last_child, + ); if context.should_linkify { if let MentionsMode::WithMentions {