зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1639287 - part 2: Make `SplitNodeTransaction::RedoTransaction()` use `HTMLEditor::DoSplitNode()` r=m_kato
Similarly, `SplitNodeTransaction::RedoTransaction()` has its own code, but it does not work well. Let's make it use `HTMLEditor::DoSplitNode()` instead. This fixes bug 1740656. Differential Revision: https://phabricator.services.mozilla.com/D132123
This commit is contained in:
Родитель
15605659bf
Коммит
b8ea6dd142
|
@ -172,58 +172,36 @@ NS_IMETHODIMP SplitNodeTransaction::RedoTransaction() {
|
|||
("%p SplitNodeTransaction::%s this=%s", this, __FUNCTION__,
|
||||
ToString(*this).c_str()));
|
||||
|
||||
if (NS_WARN_IF(!mNewLeftContent) || NS_WARN_IF(!mContainerParentNode) ||
|
||||
NS_WARN_IF(!mStartOfRightContent.IsInContentNode()) ||
|
||||
NS_WARN_IF(!mHTMLEditor)) {
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(!mNewLeftContent) ||
|
||||
NS_WARN_IF(!mContainerParentNode) ||
|
||||
NS_WARN_IF(!mStartOfRightContent.IsInContentNode()) ||
|
||||
NS_WARN_IF(!mHTMLEditor))) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
OwningNonNull<HTMLEditor> htmlEditor = *mHTMLEditor;
|
||||
OwningNonNull<nsINode> newLeftContent = *mNewLeftContent;
|
||||
OwningNonNull<nsINode> containerParentNode = *mContainerParentNode;
|
||||
const OwningNonNull<HTMLEditor> htmlEditor = *mHTMLEditor;
|
||||
const OwningNonNull<nsIContent> newLeftContent = *mNewLeftContent;
|
||||
EditorDOMPoint startOfRightContent(mStartOfRightContent);
|
||||
|
||||
// First, massage the existing node so it is in its post-split state
|
||||
ErrorResult error;
|
||||
if (startOfRightContent.IsInTextNode()) {
|
||||
Text* rightTextNode = startOfRightContent.ContainerAsText();
|
||||
htmlEditor->DoDeleteText(MOZ_KnownLive(*rightTextNode), 0,
|
||||
startOfRightContent.Offset(), error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("EditorBase::DoDeleteText() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
} else {
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> movingChildren;
|
||||
if (nsIContent* child =
|
||||
startOfRightContent.GetContainer()->GetFirstChild()) {
|
||||
movingChildren.AppendElement(*child);
|
||||
for (uint32_t i = 0; i < startOfRightContent.Offset(); i++) {
|
||||
child = child->GetNextSibling();
|
||||
if (!child) {
|
||||
break;
|
||||
}
|
||||
movingChildren.AppendElement(*child);
|
||||
}
|
||||
}
|
||||
ErrorResult error;
|
||||
for (OwningNonNull<nsIContent>& child : movingChildren) {
|
||||
newLeftContent->AppendChild(child, error);
|
||||
if (error.Failed()) {
|
||||
NS_WARNING("nsINode::AppendChild() failed");
|
||||
return error.StealNSResult();
|
||||
}
|
||||
if (RefPtr<Element> existingElement =
|
||||
mStartOfRightContent.GetContainerAsElement()) {
|
||||
nsresult rv = htmlEditor->MarkElementDirty(*existingElement);
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED))) {
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::MarkElementDirty() failed, but ignored");
|
||||
}
|
||||
MOZ_ASSERT(!error.Failed());
|
||||
// Second, re-insert the left node into the tree
|
||||
containerParentNode->InsertBefore(newLeftContent,
|
||||
startOfRightContent.GetContainer(), error);
|
||||
// InsertBefore() may call MightThrowJSException() even if there is no
|
||||
// error. We don't need the flag here.
|
||||
error.WouldReportJSException();
|
||||
NS_WARNING_ASSERTION(!error.Failed(), "nsINode::InsertBefore() failed");
|
||||
return error.StealNSResult();
|
||||
|
||||
SplitNodeResult splitNodeResult = htmlEditor->DoSplitNode(
|
||||
EditorDOMPoint(
|
||||
startOfRightContent.ContainerAsContent(),
|
||||
std::min(startOfRightContent.Offset(),
|
||||
startOfRightContent.ContainerAsContent()->Length())),
|
||||
newLeftContent);
|
||||
NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
|
||||
"HTMLEditor::DoSplitNode() failed");
|
||||
return splitNodeResult.Rv();
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
[undo-redo.html]
|
||||
[insertParagraph at start of a paragraph - first redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at start of a paragraph - second redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at middle of a paragraph - first redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at middle of a paragraph - second redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at end of a paragraph - first redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at end of a paragraph - second redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at start of a listitem - first redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at start of a listitem - second redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at middle of a listitem - first redo]
|
||||
expected: FAIL
|
||||
|
||||
[insertParagraph at middle of a listitem - second redo]
|
||||
expected: FAIL
|
Загрузка…
Ссылка в новой задаче