Bug 1766355 - part 5: Make HTMLEditor::MoveChildrenWithTransaction and HTMLEditor::MoveNodeOrChildrenWithTransaction stop touching Selection directly r=m_kato
Unfortunately, they call each other. Therefore, this patch updates these 2 methods once. Differential Revision: https://phabricator.services.mozilla.com/D146401
This commit is contained in:
@@ -4782,13 +4782,23 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContents(
|
|||||||
NS_WARNING("HTMLEditor::MoveChildrenWithTransaction() failed");
|
NS_WARNING("HTMLEditor::MoveChildrenWithTransaction() failed");
|
||||||
return moveContentsInLineResult;
|
return moveContentsInLineResult;
|
||||||
}
|
}
|
||||||
|
nsresult rv = moveContentsInLineResult.SuggestCaretPointTo(
|
||||||
|
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||||
|
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||||
|
SuggestCaret::AndIgnoreTrivialError});
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
NS_WARNING("MoveNodeResult::SuggestCaretPointTo() failed");
|
||||||
|
return MoveNodeResult(rv);
|
||||||
|
}
|
||||||
|
NS_WARNING_ASSERTION(
|
||||||
|
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
||||||
|
"MoveNodeResult::SuggestCaretPointTo() failed, but ignored");
|
||||||
offset = moveContentsInLineResult.NextInsertionPointRef().Offset();
|
offset = moveContentsInLineResult.NextInsertionPointRef().Offset();
|
||||||
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to
|
// MOZ_KnownLive because 'arrayOfContents' is guaranteed to
|
||||||
// keep it alive.
|
// keep it alive.
|
||||||
DebugOnly<nsresult> rvIgnored =
|
DebugOnly<nsresult> rvIgnored =
|
||||||
DeleteNodeWithTransaction(MOZ_KnownLive(*content));
|
DeleteNodeWithTransaction(MOZ_KnownLive(*content));
|
||||||
if (NS_WARN_IF(Destroyed())) {
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
moveContentsInLineResult.IgnoreCaretPointSuggestion();
|
|
||||||
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
||||||
}
|
}
|
||||||
NS_WARNING_ASSERTION(
|
NS_WARNING_ASSERTION(
|
||||||
@@ -4819,6 +4829,17 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContents(
|
|||||||
"ignored");
|
"ignored");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
nsresult rv = moveNodeResult.SuggestCaretPointTo(
|
||||||
|
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
||||||
|
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
||||||
|
SuggestCaret::AndIgnoreTrivialError});
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
NS_WARNING("MoveNodeResult::SuggestCaretPointTo() failed");
|
||||||
|
return MoveNodeResult(rv);
|
||||||
|
}
|
||||||
|
NS_WARNING_ASSERTION(
|
||||||
|
rv != NS_ERROR_EDITOR_NO_EDITABLE_RANGE,
|
||||||
|
"MoveNodeResult::SuggestCaretPointTo() failed, but ignored");
|
||||||
offset = moveNodeResult.NextInsertionPointRef().Offset();
|
offset = moveNodeResult.NextInsertionPointRef().Offset();
|
||||||
moveContentsInLineResult |= moveNodeResult;
|
moveContentsInLineResult |= moveNodeResult;
|
||||||
}
|
}
|
||||||
@@ -4841,31 +4862,19 @@ Result<bool, nsresult> HTMLEditor::CanMoveNodeOrChildren(
|
|||||||
}
|
}
|
||||||
|
|
||||||
MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
|
MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
|
||||||
nsIContent& aContent, const EditorDOMPoint& aPointToInsert) {
|
nsIContent& aContentToMove, const EditorDOMPoint& aPointToInsert) {
|
||||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||||
MOZ_ASSERT(aPointToInsert.IsSet());
|
MOZ_ASSERT(aPointToInsert.IsSet());
|
||||||
|
|
||||||
// Check if this node can go into the destination node
|
// Check if this node can go into the destination node
|
||||||
if (HTMLEditUtils::CanNodeContain(*aPointToInsert.GetContainer(), aContent)) {
|
if (HTMLEditUtils::CanNodeContain(*aPointToInsert.GetContainer(),
|
||||||
|
aContentToMove)) {
|
||||||
// If it can, move it there.
|
// If it can, move it there.
|
||||||
EditorDOMPoint pointToInsert(aPointToInsert);
|
EditorDOMPoint pointToInsert(aPointToInsert);
|
||||||
MoveNodeResult moveNodeResult =
|
MoveNodeResult moveNodeResult =
|
||||||
MoveNodeWithTransaction(aContent, pointToInsert);
|
MoveNodeWithTransaction(aContentToMove, pointToInsert);
|
||||||
if (moveNodeResult.isErr()) {
|
NS_WARNING_ASSERTION(moveNodeResult.isOk(),
|
||||||
NS_WARNING("HTMLEditor::MoveNodeWithTransaction() failed");
|
"HTMLEditor::MoveNodeWithTransaction() failed");
|
||||||
return MoveNodeResult(moveNodeResult.unwrapErr());
|
|
||||||
}
|
|
||||||
nsresult rv = moveNodeResult.SuggestCaretPointTo(
|
|
||||||
*this, {SuggestCaret::OnlyIfHasSuggestion,
|
|
||||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
|
|
||||||
SuggestCaret::AndIgnoreTrivialError});
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
NS_WARNING("MoveNodeResult::SuggestCaretPointTo() failed");
|
|
||||||
return MoveNodeResult(rv);
|
|
||||||
}
|
|
||||||
NS_WARNING_ASSERTION(
|
|
||||||
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
|
|
||||||
"MoveNodeResult::SuggestCaretPointTo() failed, but ignored");
|
|
||||||
// XXX This is odd to override the handled state here, but stopping this
|
// XXX This is odd to override the handled state here, but stopping this
|
||||||
// hits an NS_ASSERTION in WhiteSpaceVisibilityKeeper::
|
// hits an NS_ASSERTION in WhiteSpaceVisibilityKeeper::
|
||||||
// MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement.
|
// MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement.
|
||||||
@@ -4874,19 +4883,21 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If it can't, move its children (if any), and then delete it.
|
// If it can't, move its children (if any), and then delete it.
|
||||||
MoveNodeResult moveNodeResult;
|
MoveNodeResult moveNodeResult = [&]() MOZ_CAN_RUN_SCRIPT {
|
||||||
if (aContent.IsElement()) {
|
if (!aContentToMove.IsElement()) {
|
||||||
moveNodeResult = MoveChildrenWithTransaction(
|
return MoveNodeHandled(aPointToInsert);
|
||||||
MOZ_KnownLive(*aContent.AsElement()), aPointToInsert);
|
|
||||||
if (moveNodeResult.isErr()) {
|
|
||||||
NS_WARNING("HTMLEditor::MoveChildrenWithTransaction() failed");
|
|
||||||
return moveNodeResult;
|
|
||||||
}
|
}
|
||||||
} else {
|
MoveNodeResult moveChildrenResult = MoveChildrenWithTransaction(
|
||||||
moveNodeResult = MoveNodeHandled(aPointToInsert);
|
MOZ_KnownLive(*aContentToMove.AsElement()), aPointToInsert);
|
||||||
|
NS_WARNING_ASSERTION(moveChildrenResult.isOk(),
|
||||||
|
"HTMLEditor::MoveChildrenWithTransaction() failed");
|
||||||
|
return moveChildrenResult;
|
||||||
|
}();
|
||||||
|
if (moveNodeResult.isErr()) {
|
||||||
|
return moveNodeResult; // Already warned in the lambda.
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult rv = DeleteNodeWithTransaction(aContent);
|
nsresult rv = DeleteNodeWithTransaction(aContentToMove);
|
||||||
if (NS_WARN_IF(Destroyed())) {
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
moveNodeResult.IgnoreCaretPointSuggestion();
|
moveNodeResult.IgnoreCaretPointSuggestion();
|
||||||
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
return MoveNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
||||||
@@ -4896,16 +4907,18 @@ MoveNodeResult HTMLEditor::MoveNodeOrChildrenWithTransaction(
|
|||||||
moveNodeResult.IgnoreCaretPointSuggestion();
|
moveNodeResult.IgnoreCaretPointSuggestion();
|
||||||
return MoveNodeResult(rv);
|
return MoveNodeResult(rv);
|
||||||
}
|
}
|
||||||
if (MayHaveMutationEventListeners()) {
|
if (!MayHaveMutationEventListeners()) {
|
||||||
// Mutation event listener may make `offset` value invalid with
|
return moveNodeResult;
|
||||||
// removing some previous children while we call
|
|
||||||
// `DeleteNodeWithTransaction()` so that we should adjust it here.
|
|
||||||
if (!moveNodeResult.NextInsertionPointRef().IsSetAndValid()) {
|
|
||||||
moveNodeResult = MoveNodeHandled(
|
|
||||||
EditorDOMPoint::AtEndOf(*aPointToInsert.GetContainer()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return moveNodeResult;
|
// Mutation event listener may make `offset` value invalid with
|
||||||
|
// removing some previous children while we call
|
||||||
|
// `DeleteNodeWithTransaction()` so that we should adjust it here.
|
||||||
|
if (moveNodeResult.NextInsertionPointRef().IsSetAndValid()) {
|
||||||
|
return moveNodeResult;
|
||||||
|
}
|
||||||
|
moveNodeResult.IgnoreCaretPointSuggestion();
|
||||||
|
return MoveNodeHandled(
|
||||||
|
EditorDOMPoint::AtEndOf(*aPointToInsert.GetContainer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<bool, nsresult> HTMLEditor::CanMoveChildren(
|
Result<bool, nsresult> HTMLEditor::CanMoveChildren(
|
||||||
|
|||||||
@@ -460,10 +460,11 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
|||||||
moveNodeResult.isOk(),
|
moveNodeResult.isOk(),
|
||||||
"HTMLEditor::MoveChildrenWithTransaction() failed, but ignored");
|
"HTMLEditor::MoveChildrenWithTransaction() failed, but ignored");
|
||||||
if (moveNodeResult.isOk()) {
|
if (moveNodeResult.isOk()) {
|
||||||
// When MoveNodeResult starts to store caret point, here does not do
|
// We don't need to update selection here because of dontChangeMySelection
|
||||||
// nothing.
|
// above.
|
||||||
moveNodeResult.IgnoreCaretPointSuggestion();
|
moveNodeResult.IgnoreCaretPointSuggestion();
|
||||||
ret |= moveNodeResult;
|
ret |= moveNodeResult;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MOZ_ASSERT(!rightBlockHasContent.isErr());
|
MOZ_ASSERT(!rightBlockHasContent.isErr());
|
||||||
if (rightBlockHasContent.inspect()) {
|
if (rightBlockHasContent.inspect()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user