From 3d600c8b5d9b1667d85279a8cb2b8f1d4492c9bf Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 31 Oct 2025 12:49:41 +0000 Subject: [PATCH] Bug 1989861 - Make `HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak` consider a preceding `
` of a mailcite is necessary a=dmeehan The serializer needs to make each mailcite starts from head of a line. However, mailcite may be a blocked ``. So, its preceding `
` is not required from the HTML point of view, but we need to preserve it for the serializer. If we need this hack in some other places, we should make `HTMLEditUtils::GetFollowingUnnecessaryLineBreak()` aware of this special handling in a follow up bug. Differential Revision: https://phabricator.services.mozilla.com/D270784 --- editor/libeditor/HTMLEditor.cpp | 16 ++++ editor/libeditor/tests/mochitest.toml | 3 + ...ilcite_keep_preceding_br_after_insert.html | 73 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index b10d4abfa7cc..452a162d4f5f 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -4699,6 +4699,22 @@ nsresult HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak( return NS_OK; } if (unnecessaryLineBreak->IsHTMLBRElement()) { + // If the found unnecessary
is a preceding one of a mailcite which is a + // styled as block, we need to preserve the
element for the + // serializer to cause a line break before the mailcite. + if (IsPlaintextMailComposer()) { + const WSScanResult nextThing = + WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( + WSRunScanner::Scan::All, + unnecessaryLineBreak->After(), + BlockInlineCheck::UseComputedDisplayOutsideStyle); + if (nextThing.ReachedOtherBlockElement() && + HTMLEditUtils::IsMailCite(*nextThing.ElementPtr()) && + HTMLEditUtils::IsInlineContent( + *nextThing.ElementPtr(), BlockInlineCheck::UseHTMLDefaultStyle)) { + return NS_OK; + } + } // If the invisible break is a placeholder of ancestor inline elements, we // should not delete it to allow users to insert text with the format // specified by them. diff --git a/editor/libeditor/tests/mochitest.toml b/editor/libeditor/tests/mochitest.toml index 25597ff5c258..a1f1385d475f 100644 --- a/editor/libeditor/tests/mochitest.toml +++ b/editor/libeditor/tests/mochitest.toml @@ -479,6 +479,9 @@ skip-if = ["display == 'wayland'"] # Bug 1935188 ["test_mailcite_backspace_at_end_of_inline_reply.html"] skip-if = ["xorigin"] # Testing internal API for comm-central +["test_mailcite_keep_preceding_br_after_insert.html"] +skip-if = ["xorigin"] # Testing internal API for comm-central + ["test_mailcite_keep_trailing_br_after_delete.html"] skip-if = ["xorigin"] # Testing internal API for comm-central diff --git a/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html b/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html new file mode 100644 index 000000000000..6169b16d793c --- /dev/null +++ b/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html @@ -0,0 +1,73 @@ + + + + +Preceding <br> of a mailcite which is a blocked <span> + + + + + + + +