Bug 1770877 - part 31-2: Make HTMLEditor::InsertParagraphSeparatorAsSubAction call HandleInsertParagraphInParagraph without Selection r=m_kato

The preceding call of `InsertBRElement` may collapse selection at the inserted
padding `<br>` element.  Only when calling `HandleInsertParagraphInParagraph`,
`InsertParagraphSeparatorAsSubAction` uses `Selection`.  So, only in this case,
we need to recompute the point to split for keeping current (odd) behavior.

Note that in normal cases, using `atStartOfSelection` gets same result.
However, if there are some invisible nodes such as comment nodes, doing it
may change the behavior.  For now, we should keep the current behavior.  It
should be sorted out when we make it stop inserting `<br>` elements for the
preparation of split without checking whether it's actually necessary.

Differential Revision: https://phabricator.services.mozilla.com/D149101
This commit is contained in:
Masayuki Nakano
2022-06-22 01:52:32 +00:00
parent f60aeb4521
commit 341b28f4a6

View File

@@ -1765,31 +1765,20 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction(
// contains the word "text". The user selects "text" and types return.
// "Text" is deleted leaving an empty block. We want to put in one br to
// make block have a line. Then code further below will put in a second br.)
RefPtr<Element> insertedPaddingBRElement;
if (HTMLEditUtils::IsEmptyBlockElement(
*editableBlockElement,
{EmptyCheckOption::TreatSingleBRElementAsVisible})) {
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(editableBlockElement);
const CreateElementResult insertBRElementResult =
InsertBRElement(WithTransaction::Yes, endOfBlockParent);
CreateElementResult insertBRElementResult = InsertBRElement(
WithTransaction::Yes, EditorDOMPoint::AtEndOf(*editableBlockElement));
if (insertBRElementResult.isErr()) {
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
return EditActionIgnored(insertBRElementResult.unwrapErr());
}
// XXX Is this intentional selection change?
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
return EditActionHandled(rv);
}
NS_WARNING_ASSERTION(
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
insertBRElementResult.IgnoreCaretPointSuggestion();
MOZ_ASSERT(insertBRElementResult.GetNewNode());
insertedPaddingBRElement = insertBRElementResult.UnwrapNewNode();
}
RefPtr<Element> maybeNonEditableListItem =
@@ -1865,7 +1854,10 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction(
// Paragraphs: special rules to look for <br>s
const SplitNodeResult splitResult = HandleInsertParagraphInParagraph(
*editableBlockElement, firstRangeStartPoint, aEditingHost);
*editableBlockElement,
insertedPaddingBRElement ? EditorDOMPoint(insertedPaddingBRElement)
: atStartOfSelection,
aEditingHost);
if (splitResult.isErr()) {
NS_WARNING("HTMLEditor::HandleInsertParagraphInParagraph() failed");
return EditActionResult(splitResult.unwrapErr());