Skip to content

Commit

Permalink
Bug 1740872 - part 4: Make `HTMLEditor::FormatBlockContainerWithTrans…
Browse files Browse the repository at this point in the history
…action()` use `HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction()` r=m_kato

Depends on D131200

Differential Revision: https://phabricator.services.mozilla.com/D131201
  • Loading branch information
masayuki-nakano committed Nov 17, 2021
1 parent 8051b65 commit 47d9136
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions editor/libeditor/HTMLEditSubActionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3621,25 +3621,22 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) {
}
}
// Make sure we can put a block here.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(blockType,
pointToInsertBlock);
if (splitNodeResult.Failed()) {
Result<RefPtr<Element>, nsresult> newBlockElementOrError =
InsertElementWithSplittingAncestorsWithTransaction(blockType,
pointToInsertBlock);
if (MOZ_UNLIKELY(newBlockElementOrError.isErr())) {
NS_WARNING(
"HTMLEditor::MaybeSplitAncestorsForInsertWithTransaction() failed");
return splitNodeResult.Rv();
}
Result<RefPtr<Element>, nsresult> maybeNewBlockElement =
CreateAndInsertElementWithTransaction(blockType,
splitNodeResult.SplitPoint());
if (maybeNewBlockElement.isErr()) {
NS_WARNING("CreateAndInsertElementWithTransaction() failed");
return maybeNewBlockElement.unwrapErr();
nsPrintfCString(
"HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction("
"%s) failed",
nsAtomCString(&blockType).get())
.get());
return newBlockElementOrError.unwrapErr();
}
MOZ_ASSERT(maybeNewBlockElement.inspect());
MOZ_ASSERT(newBlockElementOrError.inspect());
// Remember our new block for postprocessing
TopLevelEditSubActionDataRef().mNewBlockElement =
maybeNewBlockElement.inspect();
newBlockElementOrError.inspect();
// Delete anything that was in the list of nodes
while (!arrayOfContents.IsEmpty()) {
OwningNonNull<nsIContent>& content = arrayOfContents[0];
Expand All @@ -3659,7 +3656,7 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) {
restoreSelectionLater.Abort();
// Put selection in new block
rv = CollapseSelectionToStartOf(
MOZ_KnownLive(*maybeNewBlockElement.inspect()));
MOZ_KnownLive(*newBlockElementOrError.inspect()));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::CollapseSelectionToStartOf() failed");
return rv;
Expand Down

0 comments on commit 47d9136

Please sign in to comment.