From aeca189ce4c0a8802129b7af7cb0537592e33790 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 17 Aug 2016 21:44:05 +0300 Subject: [PATCH] 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
. (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 --- editor/libeditor/HTMLEditRules.cpp | 22 ++++++++++--------- .../meta/editing/other/delete.html.ini | 6 ----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp index d163bb2a799b..80e75dcacb7d 100644 --- a/editor/libeditor/HTMLEditRules.cpp +++ b/editor/libeditor/HTMLEditRules.cpp @@ -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 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 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); diff --git a/testing/web-platform/meta/editing/other/delete.html.ini b/testing/web-platform/meta/editing/other/delete.html.ini index 1256628f2ca1..1f0142625982 100644 --- a/testing/web-platform/meta/editing/other/delete.html.ini +++ b/testing/web-platform/meta/editing/other/delete.html.ini @@ -12,9 +12,3 @@ [5: "



" 1,0-0,0 forwarddelete] expected: FAIL - [13: "



\\n" 1,0 delete] - expected: FAIL - - [15: "\\n

x



\\n" 3,0,0 delete] - expected: FAIL -