Bug 1265800 part 3 - Move cursor into all adjacent nodes after delete; r=masayuki

When deleting, we previously would only move the cursor back into the
previous block if the last leaf node was a text node, for some reason.
We should move into the previous block in other cases as well, like if
the leaf node is a collapsed <br>.  (Probably it's not correct to move
backward into tables, but that already was happening if the table had
text at the end.  There may be other cases where this is wrong.)

MozReview-Commit-ID: 8e0dTU3lNYO
This commit is contained in:
Aryeh Gregor 2016-08-17 21:44:05 +03:00
parent c0a463e1dd
commit aeca189ce4
2 changed files with 12 additions and 16 deletions

View File

@ -4824,24 +4824,26 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
}
} else {
if (aAction == nsIEditor::eNext) {
// Adjust selection to be right after it.
res = aSelection->Collapse(blockParent, offset + 1);
NS_ENSURE_SUCCESS(res, res);
// Move to the start of the next node if it's a text.
// Move to the start of the next node, if any
nsCOMPtr<nsIContent> nextNode = mHTMLEditor->GetNextNode(blockParent,
offset + 1, true);
if (nextNode && mHTMLEditor->IsTextNode(nextNode)) {
res = aSelection->Collapse(nextNode, 0);
if (nextNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
res = aSelection->Collapse(pt.node, pt.offset);
NS_ENSURE_SUCCESS(res, res);
} else {
// Adjust selection to be right after it.
res = aSelection->Collapse(blockParent, offset + 1);
NS_ENSURE_SUCCESS(res, res);
}
} else {
// Move to the end of the previous node if it's a text.
// Move to the end of the previous node
nsCOMPtr<nsIContent> priorNode = mHTMLEditor->GetPriorNode(blockParent,
offset,
true);
if (priorNode && mHTMLEditor->IsTextNode(priorNode)) {
res = aSelection->Collapse(priorNode, priorNode->TextLength());
if (priorNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
res = aSelection->Collapse(pt.node, pt.offset);
NS_ENSURE_SUCCESS(res, res);
} else {
res = aSelection->Collapse(blockParent, offset + 1);

View File

@ -12,9 +12,3 @@
[5: "<p><br></p><p><br></p>" 1,0-0,0 forwarddelete]
expected: FAIL
[13: "<p><br></p><p><br></p>\\n" 1,0 delete]
expected: FAIL
[15: "\\n<p><tt>x</tt></p><p><tt><br></tt></p><p><tt><br></tt></p>\\n" 3,0,0 delete]
expected: FAIL