Bug 1968820 - Make HTMLEditor::InsertPaddingBRElementIfNeeded() put <br> before the mail-quote a=dmeehan

When we find a block boundary, it may be current block's boundary or
other block's boundary.  The lambda assume only the former, but the
STR of this bug hits the latter case.

So, when user modifies the text before a mail-quote which is a block of
`<span>` element should put `<br>` before it rather than end of it.

Differential Revision: https://phabricator.services.mozilla.com/D270782
This commit is contained in:
Masayuki Nakano
2025-10-31 12:49:41 +00:00
committed by dmeehan@mozilla.com
parent 3f6ceff21f
commit 8e53bd4fcd
3 changed files with 94 additions and 1 deletions

View File

@@ -12042,7 +12042,9 @@ HTMLEditor::InsertPaddingBRElementIfNeeded(
HTMLEditUtils::IsInlineContent( HTMLEditUtils::IsInlineContent(
*nextVisibleThing.ElementPtr(), *nextVisibleThing.ElementPtr(),
BlockInlineCheck::UseHTMLDefaultStyle)) { BlockInlineCheck::UseHTMLDefaultStyle)) {
return EditorDOMPoint::AtEndOf(*nextVisibleThing.ElementPtr()); return nextVisibleThing.ReachedCurrentBlockBoundary()
? EditorDOMPoint::AtEndOf(*nextVisibleThing.ElementPtr())
: EditorDOMPoint(nextVisibleThing.ElementPtr());
} }
} }
return HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible(aPoint, return HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible(aPoint,

View File

@@ -476,6 +476,9 @@ skip-if = ["display == 'wayland'"] # Bug 1935188
["test_label_contenteditable.html"] ["test_label_contenteditable.html"]
["test_mailcite_backspace_at_end_of_inline_reply.html"]
skip-if = ["xorigin"] # Testing internal API for comm-central
["test_mailcite_keep_trailing_br_after_delete.html"] ["test_mailcite_keep_trailing_br_after_delete.html"]
skip-if = ["xorigin"] # Testing internal API for comm-central skip-if = ["xorigin"] # Testing internal API for comm-central

View File

@@ -0,0 +1,88 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Trailing &lt;br&gt; of a mailcite which is a blocked &lt;span&gt;</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script>
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
const iframe = document.querySelector("iframe");
await new Promise(resolve => {
if (iframe.contentDocument?.readyState == "complete") {
resolve();
return;
}
iframe.addEventListener("load", resolve, {once: true});
});
const win = iframe.contentWindow;
getEditor(win).flags |=
SpecialPowers.Ci.nsIEditor.eEditorMailMask | SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask;
const doc = iframe.contentDocument;
const mailEditor = getEditorMailSupport(win);
win.focus();
doc.body.focus();
const mailciteStyle = "white-space: pre-wrap; display: block; width: 98vw;";
const mailcite = SpecialPowers.unwrap(
mailEditor.insertAsCitedQuotation("Hi there, How are you doing.", "", false)
);
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there, How are you doing.<br><br></span><br><br>`,
"nsIEditorMailSupport.insertAsCitedQuotation() should insert a mailcite span"
);
// Put caret before "How".
win.getSelection().collapse(mailcite.firstChild, "> Hi there, ".length);
doc.execCommand("insertParagraph"); // Type Enter
doc.execCommand("insertText", false, "Here is inline reply.");
doc.execCommand("delete"); // Type Backspace
doc.execCommand("delete"); // Type Backspace
doc.execCommand("delete"); // Type Backspace
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there, <br></span>` + // FIXME: The last white-space should be an NBSP...
`Here is inline rep<br>` + // The last <br> is required for giving different lines after serializing this as plaintext.
`<span style="${mailciteStyle}">How are you doing.<br><br></span><br><br>`,
"Backspace shouldn't cause inserting linebreaks at end of the second quote #1"
);
doc.execCommand("delete"); // Type Backspace
doc.execCommand("delete"); // Type Backspace
doc.execCommand("delete"); // Type Backspace
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there, <br></span>` + // FIXME: The last white-space should be an NBSP...
`Here is inline&nbsp;<br>` + // The last <br> is required for giving different lines after serializing this as plaintext.
`<span style="${mailciteStyle}">How are you doing.<br><br></span><br><br>`,
"Backspace shouldn't cause inserting linebreaks at end of the second quote #2"
);
doc.execCommand("delete"); // Type Backspace
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there, <br></span>` + // FIXME: The last white-space should be an NBSP...
`Here is inline<br>` + // The last <br> is required for giving different lines after serializing this as plaintext.
`<span style="${mailciteStyle}">How are you doing.<br><br></span><br><br>`,
"Backspace shouldn't cause inserting linebreaks at end of the second quote #3"
);
SimpleTest.finish();
});
function getEditor(aWindow) {
const editingSession = SpecialPowers.wrap(aWindow).docShell.editingSession;
return editingSession.getEditorForWindow(aWindow);
}
function getEditorMailSupport(aWindow) {
return getEditor(aWindow).QueryInterface(SpecialPowers.Ci.nsIEditorMailSupport);
}
</script>
</head>
<body>
<iframe srcdoc="<body contenteditable><br><br></body>"></iframe>
</body>
</html>