Bug 1391165 - part3: TextEditRules::CollapseSelectionToTrailingBRIfNeeded() should use EditorBase::GetChildOffset() only when it's necessary r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 17 Aug 2017 16:48:49 +0900
changeset 648951 c792b7797cbbc5f05f1f377c87fa81c94e9c00ee
parent 648950 86b8a20f73e0d15893913f7d849d069c18e1b4f3
child 648952 da7bd11fed7a1dd03310f065d9f2721d7c06ea5f
push id74932
push usermasayuki@d-toybox.com
push dateFri, 18 Aug 2017 14:10:13 +0000
reviewerssmaug
bugs1391165
milestone57.0a1
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
editor/libeditor/TextEditRules.cpp
--- 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>