Bug 1391165 - part3: TextEditRules::CollapseSelectionToTrailingBRIfNeeded() should use EditorBase::GetChildOffset() only when it's necessary r?smaug
In most cases, TextEditRules::CollapseSelectionToTrailingBRIfNeeded() doesn't
use the index anymore. Therefore, it should stop using
EditorBase::GetNodeLocation() and use EditorBase::GetChildOffset() only when
the offset is necessary.
MozReview-Commit-ID: 9vGcLnTUnsu
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -500,32 +500,30 @@ TextEditRules::CollapseSelectionToTraili
return NS_OK; // Nothing to do if we're not at a text node.
}
// nothing to do if we're not at the end of the text node
if (selOffset != static_cast<int32_t>(selNode->Length())) {
return NS_OK;
}
- int32_t parentOffset;
- nsINode* parentNode =
- EditorBase::GetNodeLocation(selNode, &parentOffset);
-
NS_ENSURE_STATE(mTextEditor);
nsINode* root = mTextEditor->GetRoot();
if (NS_WARN_IF(!root)) {
return NS_ERROR_NULL_POINTER;
}
+ nsINode* parentNode = selNode->GetParentNode();
if (parentNode != root) {
return NS_OK;
}
nsINode* nextNode = selNode->GetNextSibling();
if (nextNode && TextEditUtils::IsMozBR(nextNode)) {
- rv = aSelection->Collapse(parentNode, parentOffset + 1);
+ int32_t offsetInParent = EditorBase::GetChildOffset(selNode, parentNode);
+ rv = aSelection->Collapse(parentNode, offsetInParent + 1);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}
static inline already_AddRefed<nsINode>