From 341b28f4a639ff3dd2e825033c8069e706ea9b51 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 22 Jun 2022 01:52:32 +0000 Subject: [PATCH] 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 `
` 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 `
` elements for the preparation of split without checking whether it's actually necessary. Differential Revision: https://phabricator.services.mozilla.com/D149101 --- editor/libeditor/HTMLEditSubActionHandler.cpp | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp index 37e0df6ed8ba..231eb45f8556 100644 --- a/editor/libeditor/HTMLEditSubActionHandler.cpp +++ b/editor/libeditor/HTMLEditSubActionHandler.cpp @@ -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 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 maybeNonEditableListItem = @@ -1865,7 +1854,10 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction( // Paragraphs: special rules to look for
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());