Bug 1314790 - Part 1. GetGoodSelPointForNode doesn't work with ePrevousWord action. r?masayuki
Although GetGoodSelPointForNode only supports ePrevious or eNext as action, we use other action. So we should add aseetion for it.
MozReview-Commit-ID: 3gLFFTAdNxU
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2506,37 +2506,47 @@ HTMLEditRules::InsertBRIfNeeded(Selectio
}
/**
* GetGoodSelPointForNode() finds where at a node you would want to set the
* selection if you were trying to have a caret next to it. Always returns a
* valid value (unless mHTMLEditor has gone away).
*
* @param aNode The node
- * @param aAction Which edge to find: eNext indicates beginning,
- * ePrevious ending.
+ * @param aAction Which edge to find:
+ * eNext/eNextWord/eToEndOfLine indicates beginning,
+ * ePrevious/PreviousWord/eToBeginningOfLine ending.
*/
EditorDOMPoint
HTMLEditRules::GetGoodSelPointForNode(nsINode& aNode,
nsIEditor::EDirection aAction)
{
+ MOZ_ASSERT(aAction == nsIEditor::eNext ||
+ aAction == nsIEditor::eNextWord ||
+ aAction == nsIEditor::ePrevious ||
+ aAction == nsIEditor::ePreviousWord ||
+ aAction == nsIEditor::eToBeginningOfLine ||
+ aAction == nsIEditor::eToEndOfLine);
+
+ bool isPreviousAction = (aAction == nsIEditor::ePrevious ||
+ aAction == nsIEditor::ePreviousWord ||
+ aAction == nsIEditor::eToBeginningOfLine);
+
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
if (aNode.GetAsText() || mHTMLEditor->IsContainer(&aNode) ||
NS_WARN_IF(!aNode.GetParentNode())) {
- return EditorDOMPoint(&aNode,
- aAction == nsIEditor::ePrevious ? aNode.Length() : 0);
+ return EditorDOMPoint(&aNode, isPreviousAction ? aNode.Length() : 0);
}
EditorDOMPoint ret;
ret.node = aNode.GetParentNode();
ret.offset = ret.node ? ret.node->IndexOf(&aNode) : -1;
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
if ((!aNode.IsHTMLElement(nsGkAtoms::br) ||
- mHTMLEditor->IsVisBreak(&aNode)) &&
- aAction == nsIEditor::ePrevious) {
+ mHTMLEditor->IsVisBreak(&aNode)) && isPreviousAction) {
ret.offset++;
}
return ret;
}
/**
* This method is used to join two block elements. The right element is always
@@ -4837,42 +4847,47 @@ HTMLEditRules::CheckForEmptyBlock(nsINod
// Adjust selection to be right before it
rv = aSelection->Collapse(listParent, listOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
// Else just let selection percolate up. We'll adjust it in
// AfterEdit()
}
} else {
- if (aAction == nsIEditor::eNext) {
+ if (aAction == nsIEditor::eNext || aAction == nsIEditor::eNextWord ||
+ aAction == nsIEditor::eToEndOfLine) {
// Move to the start of the next node, if any
nsCOMPtr<nsIContent> nextNode = htmlEditor->GetNextNode(blockParent,
offset + 1, true);
if (nextNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
nsresult rv = aSelection->Collapse(pt.node, pt.offset);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// Adjust selection to be right after it.
nsresult rv = aSelection->Collapse(blockParent, offset + 1);
NS_ENSURE_SUCCESS(rv, rv);
}
- } else {
+ } else if (aAction == nsIEditor::ePrevious ||
+ aAction == nsIEditor::ePreviousWord ||
+ aAction == nsIEditor::eToBeginningOfLine) {
// Move to the end of the previous node
nsCOMPtr<nsIContent> priorNode = htmlEditor->GetPriorNode(blockParent,
offset,
true);
if (priorNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
nsresult rv = aSelection->Collapse(pt.node, pt.offset);
NS_ENSURE_SUCCESS(rv, rv);
} else {
nsresult rv = aSelection->Collapse(blockParent, offset + 1);
NS_ENSURE_SUCCESS(rv, rv);
}
+ } else {
+ NS_RUNTIMEABORT("CheckForEmptyBlock doesn't support this action yet");
}
}
NS_ENSURE_STATE(htmlEditor);
*aHandled = true;
nsresult rv = htmlEditor->DeleteNode(emptyBlock);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;