Bug 1870222 - part 4: Make HTMLEditor treat non-editable content as visible when splitting a paragraph r=m_kato

Depends on D196815

Differential Revision: https://phabricator.services.mozilla.com/D196816
This commit is contained in:
Masayuki Nakano 2023-12-25 12:54:07 +00:00
parent 85945dea72
commit 3a1fc63ab7
2 changed files with 18 additions and 10 deletions

View File

@ -2087,8 +2087,7 @@ HTMLEditor::InsertParagraphSeparatorAsSubAction(const Element& aEditingHost) {
RefPtr<Element> insertedPaddingBRElement;
if (HTMLEditUtils::IsEmptyBlockElement(
*editableBlockElement,
{EmptyCheckOption::TreatSingleBRElementAsVisible,
EmptyCheckOption::TreatNonEditableContentAsInvisible},
{EmptyCheckOption::TreatSingleBRElementAsVisible},
BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
Result<CreateElementResult, nsresult> insertBRElementResult =
InsertBRElement(WithTransaction::Yes,
@ -8606,9 +8605,7 @@ Result<SplitNodeResult, nsresult> HTMLEditor::SplitParagraphWithTransaction(
}
if (!HTMLEditUtils::IsEmptyNode(
aElement,
{EmptyCheckOption::TreatSingleBRElementAsVisible,
EmptyCheckOption::TreatNonEditableContentAsInvisible})) {
aElement, {EmptyCheckOption::TreatSingleBRElementAsVisible})) {
return NS_OK;
}
@ -8640,9 +8637,7 @@ Result<SplitNodeResult, nsresult> HTMLEditor::SplitParagraphWithTransaction(
return Err(rv);
}
if (HTMLEditUtils::IsEmptyNode(
*rightDivOrParagraphElement,
{EmptyCheckOption::TreatNonEditableContentAsInvisible})) {
if (HTMLEditUtils::IsEmptyNode(*rightDivOrParagraphElement)) {
// If the right paragraph is empty, it might have an empty inline element
// (which may contain other empty inline containers) and optionally a <br>
// element which may not be in the deepest inline element.
@ -10519,10 +10514,12 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(const EditorDOMRange& aRange) {
// nodes we require to be empty.
HTMLEditUtils::EmptyCheckOptions options{
EmptyCheckOption::TreatListItemAsVisible,
EmptyCheckOption::TreatTableCellAsVisible,
EmptyCheckOption::TreatNonEditableContentAsInvisible};
EmptyCheckOption::TreatTableCellAsVisible};
if (!isMailCite) {
options += EmptyCheckOption::TreatSingleBRElementAsVisible;
} else {
// XXX Maybe unnecessary to specify this.
options += EmptyCheckOption::TreatNonEditableContentAsInvisible;
}
if (!HTMLEditUtils::IsEmptyNode(*content, options)) {
return false;

View File

@ -2410,4 +2410,15 @@ var browserTests = [
"<ul><li><span style=\"color:rgb(0, 0, 255)\"><span style=\"background-color:rgb(0, 0, 255)\">foo</span></span><br></li><li><span style=\"color:rgb(0, 0, 255)\"><span style=\"background-color:rgb(0, 0, 255)\"><br></span></span></li></ul>"],
[true,true],
{"insertparagraph":[false,false,"",false,false,""]}],
["<p>[X]<span contenteditable=false>abc</span></p>",
[["insertparagraph",""]],
"<p><br></p><p><span contenteditable=\"false\">abc</span></p>",
[true],
{}],
["<p><span contenteditable=false>abc</span>[X]</p>",
[["insertparagraph",""]],
"<p><span contenteditable=\"false\">abc</span></p><p><br></p>",
[true],
{}],
]