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 b27e9aef..0a8e1db1 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 @@ -75,7 +75,10 @@ impl<'a> InlineHtmlBuilder<'a> { /// constructed, if any. pub(super) fn build(self) -> (String, Option>) { let mut inner = self.inner; - let ellipsis = self.ellipsis | self.truncated; + + // Do not add an ellipsis on an empty inline element, we just want to get rid of + // it. + let ellipsis = (self.ellipsis && !inner.is_empty()) | self.truncated; if ellipsis { inner.append_ellipsis(); @@ -222,8 +225,8 @@ 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, and after a - // newline. + // Collapse whitespaces and remove them 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, diff --git a/src/session/view/content/room_history/message_row/text/tests.rs b/src/session/view/content/room_history/message_row/text/tests.rs index 4258b2e7..f14d34f2 100644 --- a/src/session/view/content/room_history/message_row/text/tests.rs +++ b/src/session/view/content/room_history/message_row/text/tests.rs @@ -18,6 +18,12 @@ fn single_line() { assert_eq!(s, "A simple text…"); assert!(pills.is_none()); + + let html = Html::parse("\nThis is a paragraph
\n\nThis is another paragraph\n"); + let (s, pills) = InlineHtmlBuilder::new(true, false).build_with_nodes(html.children()); + + assert_eq!(s, "This is a paragraph…"); + assert!(pills.is_none()); } #[test] diff --git a/src/session/view/content/room_history/message_row/text/widgets.rs b/src/session/view/content/room_history/message_row/text/widgets.rs index 94083eea..376220ae 100644 --- a/src/session/view/content/room_history/message_row/text/widgets.rs +++ b/src/session/view/content/room_history/message_row/text/widgets.rs @@ -64,13 +64,15 @@ pub(super) fn widget_for_html_nodes( let is_last = i == (len - 1); let add_ellipsis = add_ellipsis || (config.ellipsize && !is_last); - match group { + let widget = match group { NodeGroup::Inline(inline_nodes) => { - if let Some(widget) = + let Some(widget) = label_for_inline_html(inline_nodes, config, add_ellipsis, sender_name) - { - children.push(widget); - } + else { + continue; + }; + + widget } NodeGroup::Block(block_node) => { let Some(widget) = @@ -90,9 +92,11 @@ pub(super) fn widget_for_html_nodes( children.push(label.upcast()); } - children.push(widget); + widget } - } + }; + + children.push(widget); if config.ellipsize { // Stop at the first constructed child. @@ -121,6 +125,7 @@ pub(super) fn widget_for_html_nodes( } /// A group of nodes, representing the nodes contained in a single widget. +#[derive(Debug)] enum NodeGroup { /// A group of inline nodes. Inline(Vec),