--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2654,17 +2654,16 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
int32_t rightOffset = 0;
int32_t leftOffset = -1;
// offset below is where you find yourself in rightBlock when you traverse
// upwards from leftBlock
- EditActionResult ret(NS_OK);
if (EditorUtils::IsDescendantOf(leftBlock, rightBlock, &rightOffset)) {
// Tricky case. Left block is inside right block. Do ws adjustment. This
// just destroys non-visible ws at boundaries we will be joining.
rightOffset++;
nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kBlockEnd,
leftBlock);
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -2690,16 +2689,17 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
return EditActionIgnored(NS_ERROR_UNEXPECTED);
}
rightBlock = trackingRightBlock->GetParentElement();
}
}
// Do br adjustment.
nsCOMPtr<Element> brNode =
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
+ EditActionResult ret(NS_OK);
if (mergeLists) {
// The idea here is to take all children in rightList that are past
// offset, and pull them into leftlist.
for (nsCOMPtr<nsIContent> child = rightList->GetChildAt(offset);
child; child = rightList->GetChildAt(rightOffset)) {
rv = htmlEditor->MoveNode(child, leftList, -1);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
@@ -2713,19 +2713,22 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
if (retMoveBlock.Handled()) {
ret.MarkAsHandled();
}
}
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
ret.MarkAsHandled();
}
+ return ret;
+ }
+
// Offset below is where you find yourself in leftBlock when you traverse
// upwards from rightBlock
- } else if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
+ if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
// Tricky case. Right block is inside left block. Do ws adjustment. This
// just destroys non-visible ws at boundaries we will be joining.
nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kBlockStart,
rightBlock);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
@@ -2750,16 +2753,17 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
return EditActionIgnored(NS_ERROR_UNEXPECTED);
}
leftBlock = trackingLeftBlock->GetParentElement();
}
}
// Do br adjustment.
nsCOMPtr<Element> brNode =
CheckForInvisibleBR(*leftBlock, BRLocation::beforeBlock, leftOffset);
+ EditActionResult ret(NS_OK);
if (mergeLists) {
// XXX Why do we ignore the result of MoveContents()?
EditActionResult retMoveContents =
MoveContents(*rightList, *leftList, &leftOffset);
if (retMoveContents.Handled()) {
ret.MarkAsHandled();
}
} else {
@@ -2825,57 +2829,59 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
previousContentOffset, rightOffset);
if (NS_WARN_IF(ret.Failed())) {
return ret;
}
}
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
ret.MarkAsHandled();
}
+ return ret;
+ }
+
+ // Normal case. Blocks are siblings, or at least close enough. An example
+ // of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
+ // first li and the p are not true siblings, but we still want to join them
+ // if you backspace from li into p.
+
+ // Adjust whitespace at block boundaries
+ nsresult rv =
+ WSRunObject::PrepareToJoinBlocks(htmlEditor, leftBlock, rightBlock);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return EditActionIgnored(rv);
+ }
+ // Do br adjustment.
+ nsCOMPtr<Element> brNode =
+ CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
+ EditActionResult ret(NS_OK);
+ if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
+ rightBlock->NodeInfo()->NameAtom()) {
+ // Nodes are same type. merge them.
+ EditorDOMPoint pt = JoinNodesSmart(*leftBlock, *rightBlock);
+ if (pt.node && mergeLists) {
+ nsCOMPtr<Element> newBlock;
+ ConvertListType(rightBlock, getter_AddRefs(newBlock),
+ existingList, nsGkAtoms::li);
+ }
+ ret.MarkAsHandled();
} else {
- // Normal case. Blocks are siblings, or at least close enough. An example
- // of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
- // first li and the p are not true siblings, but we still want to join them
- // if you backspace from li into p.
-
- // Adjust whitespace at block boundaries
- nsresult rv =
- WSRunObject::PrepareToJoinBlocks(htmlEditor, leftBlock, rightBlock);
+ // Nodes are dissimilar types.
+ ret |= MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
+ if (NS_WARN_IF(ret.Failed())) {
+ return ret;
+ }
+ }
+ if (brNode) {
+ rv = htmlEditor->DeleteNode(brNode);
+ // XXX In other top level if blocks, the result of DeleteNode()
+ // is ignored. Why does only this result is respected?
if (NS_WARN_IF(NS_FAILED(rv))) {
- return EditActionIgnored(rv);
- }
- // Do br adjustment.
- nsCOMPtr<Element> brNode =
- CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
- if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
- rightBlock->NodeInfo()->NameAtom()) {
- // Nodes are same type. merge them.
- EditorDOMPoint pt = JoinNodesSmart(*leftBlock, *rightBlock);
- if (pt.node && mergeLists) {
- nsCOMPtr<Element> newBlock;
- ConvertListType(rightBlock, getter_AddRefs(newBlock),
- existingList, nsGkAtoms::li);
- }
- ret.MarkAsHandled();
- } else {
- // Nodes are dissimilar types.
- ret |= MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
- if (NS_WARN_IF(ret.Failed())) {
- return ret;
- }
- }
- if (brNode) {
- rv = htmlEditor->DeleteNode(brNode);
- // XXX In other top level if/else-if blocks, the result of DeleteNode()
- // is ignored. Why does only this result is respected?
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return ret.SetResult(rv);
- }
- ret.MarkAsHandled();
- }
+ return ret.SetResult(rv);
+ }
+ ret.MarkAsHandled();
}
return ret;
}
EditActionResult
HTMLEditRules::MoveBlock(Element& aLeftBlock,
Element& aRightBlock,
int32_t aLeftOffset,
@@ -2941,32 +2947,32 @@ HTMLEditRules::MoveNodeSmart(nsIContent&
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
if (*aInOutDestOffset != -1) {
(*aInOutDestOffset)++;
}
// XXX Should we check if the node is actually moved in this case?
return EditActionHandled();
- } else {
- // If it can't, move its children (if any), and then delete it.
- EditActionResult ret(NS_OK);
- if (aNode.IsElement()) {
- ret = MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset);
- if (NS_WARN_IF(ret.Failed())) {
- return ret;
- }
- }
-
- nsresult rv = htmlEditor->DeleteNode(&aNode);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return ret.SetResult(rv);
- }
- return ret.MarkAsHandled();
- }
+ }
+
+ // If it can't, move its children (if any), and then delete it.
+ EditActionResult ret(NS_OK);
+ if (aNode.IsElement()) {
+ ret = MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset);
+ if (NS_WARN_IF(ret.Failed())) {
+ return ret;
+ }
+ }
+
+ nsresult rv = htmlEditor->DeleteNode(&aNode);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return ret.SetResult(rv);
+ }
+ return ret.MarkAsHandled();
}
EditActionResult
HTMLEditRules::MoveContents(Element& aElement,
Element& aDestElement,
int32_t* aInOutDestOffset)
{
MOZ_ASSERT(aInOutDestOffset);