--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2920,119 +2920,120 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
rightBlock->GetParentNode() == leftBlock) {
return EditActionHandled();
}
// Special rule here: if we are trying to join list items, and they are in
// different lists, join the lists instead.
bool mergeLists = false;
nsAtom* existingList = nsGkAtoms::_empty;
- EditorDOMPoint childInBlock;
+ EditorDOMPoint atChildInBlock;
nsCOMPtr<Element> leftList, rightList;
if (HTMLEditUtils::IsListItem(leftBlock) &&
HTMLEditUtils::IsListItem(rightBlock)) {
leftList = leftBlock->GetParentElement();
rightList = rightBlock->GetParentElement();
if (leftList && rightList && leftList != rightList &&
- !EditorUtils::IsDescendantOf(*leftList, *rightBlock, &childInBlock) &&
- !EditorUtils::IsDescendantOf(*rightList, *leftBlock, &childInBlock)) {
+ !EditorUtils::IsDescendantOf(*leftList, *rightBlock, &atChildInBlock) &&
+ !EditorUtils::IsDescendantOf(*rightList, *leftBlock, &atChildInBlock)) {
// There are some special complications if the lists are descendants of
// the other lists' items. Note that it is okay for them to be
// descendants of the other lists themselves, which is the usual case for
// sublists in our implementation.
- MOZ_DIAGNOSTIC_ASSERT(!childInBlock.IsSet());
+ MOZ_DIAGNOSTIC_ASSERT(!atChildInBlock.IsSet());
leftBlock = leftList;
rightBlock = rightList;
mergeLists = true;
existingList = leftList->NodeInfo()->NameAtom();
}
}
AutoTransactionsConserveSelection dontChangeMySelection(htmlEditor);
// offset below is where you find yourself in rightBlock when you traverse
// upwards from leftBlock
- EditorDOMPoint rightBlockChild;
- if (EditorUtils::IsDescendantOf(*leftBlock, *rightBlock, &rightBlockChild)) {
+ EditorDOMPoint atRightBlockChild;
+ if (EditorUtils::IsDescendantOf(*leftBlock, *rightBlock,
+ &atRightBlockChild)) {
// Tricky case. Left block is inside right block. Do ws adjustment. This
// just destroys non-visible ws at boundaries we will be joining.
- rightBlockChild.AdvanceOffset();
+ DebugOnly<bool> advanced = atRightBlockChild.AdvanceOffset();
+ NS_WARNING_ASSERTION(advanced,
+ "Failed to advance offset to after child of rightBlock, "
+ "leftBlock is a descendant of the child");
nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kBlockEnd,
leftBlock);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
{
// We can't just track rightBlock because it's an Element.
- AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater, &rightBlockChild);
+ AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater, &atRightBlockChild);
rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kAfterBlock,
- rightBlock,
- rightBlockChild.Offset());
+ atRightBlockChild.Container(),
+ atRightBlockChild.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
// XXX AutoTrackDOMPoint instance, tracker, hasn't been destroyed here.
// Do we really need to do update rightBlock here??
- MOZ_ASSERT(rightBlock == rightBlockChild.Container());
- if (rightBlockChild.Container()->IsElement()) {
- rightBlock = rightBlockChild.Container()->AsElement();
+ MOZ_ASSERT(rightBlock == atRightBlockChild.Container());
+ if (atRightBlockChild.Container()->IsElement()) {
+ rightBlock = atRightBlockChild.Container()->AsElement();
} else {
- if (NS_WARN_IF(!rightBlockChild.Container()->GetParentElement())) {
+ if (NS_WARN_IF(!atRightBlockChild.Container()->GetParentElement())) {
return EditActionIgnored(NS_ERROR_UNEXPECTED);
}
- rightBlock = rightBlockChild.Container()->GetParentElement();
- }
- }
+ rightBlock = atRightBlockChild.Container()->GetParentElement();
+ }
+ }
+
// Do br adjustment.
nsCOMPtr<Element> brNode =
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
EditActionResult ret(NS_OK);
if (mergeLists) {
+ MOZ_DIAGNOSTIC_ASSERT(!atChildInBlock.IsSet());
// The idea here is to take all children in rightList that are past
// offset, and pull them into leftlist.
- // XXX Looks like that when mergeLists is true, childInBlock has never
- // been set. So, this block must be dead code.
- MOZ_DIAGNOSTIC_ASSERT(childInBlock.IsSet());
- uint32_t offset = rightBlockChild.Offset();
- for (nsCOMPtr<nsIContent> child = childInBlock.GetChildAtOffset();
- child; child = rightList->GetChildAt(offset)) {
- rv = htmlEditor->MoveNode(child, leftList, -1);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return EditActionIgnored(rv);
- }
- }
- // XXX Should this set to true only when above for loop moves the node?
+ int32_t append = -1;
+ ret = MoveContents(*rightList, *leftList, &append);
+ if (NS_WARN_IF(ret.Failed())) {
+ return ret;
+ }
+ // XXX Should this set to true only when above MoveContents moves some
+ // list items actually?
ret.MarkAsHandled();
- // childInBlock and rightBlockChild were moved to leftList. So, they
+ // atChildInBlock and atRightBlockChild were moved to leftList. So, they
// are now invalid.
- rightBlockChild.Clear();
- childInBlock.Clear();
+ atRightBlockChild.Clear();
+ atChildInBlock.Clear();
} else {
// XXX Why do we ignore the result of MoveBlock()?
EditActionResult retMoveBlock =
MoveBlock(*leftBlock, *rightBlock,
- -1, rightBlockChild.Offset());
+ -1, atRightBlockChild.Offset());
if (retMoveBlock.Handled()) {
ret.MarkAsHandled();
}
// Now, all children of rightBlock were moved to leftBlock. So,
- // rightBlockChild is now invalid.
- rightBlockChild.Clear();
+ // atRightBlockChild is now invalid.
+ atRightBlockChild.Clear();
}
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
ret.MarkAsHandled();
}
return ret;
}
- MOZ_DIAGNOSTIC_ASSERT(!rightBlockChild.IsSet());
+ MOZ_DIAGNOSTIC_ASSERT(!atRightBlockChild.IsSet());
// Offset below is where you find yourself in leftBlock when you traverse
// upwards from rightBlock
EditorDOMPoint leftBlockChild;
if (EditorUtils::IsDescendantOf(*rightBlock, *leftBlock, &leftBlockChild)) {
// 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,
@@ -3141,17 +3142,17 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
}
}
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
ret.MarkAsHandled();
}
return ret;
}
- MOZ_DIAGNOSTIC_ASSERT(!rightBlockChild.IsSet());
+ MOZ_DIAGNOSTIC_ASSERT(!atRightBlockChild.IsSet());
MOZ_DIAGNOSTIC_ASSERT(!leftBlockChild.IsSet());
// 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