Bug 1406215 - Part 2: Remove the usage of nsINode::GetChildAt() from nsTextServicesDocument::GetCollapsedSelection(); r=masayuki
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 05 Oct 2017 19:47:28 -0400
changeset 676126 3edd962139b648d3b8b22e70d5a17af3414de6e4
parent 676125 756a3fa73513fdddaa4cbc03f3af2464cee6c5ff
child 676127 d1a430da8fe8332956816c94027947a07805fc8a
push id83398
push userbmo:rail@mozilla.com
push dateFri, 06 Oct 2017 17:12:44 +0000
reviewersmasayuki
bugs1406215
milestone58.0a1
Bug 1406215 - Part 2: Remove the usage of nsINode::GetChildAt() from nsTextServicesDocument::GetCollapsedSelection(); r=masayuki
editor/txtsvc/nsTextServicesDocument.cpp
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -2384,23 +2384,20 @@ nsTextServicesDocument::GetCollapsedSele
   nsIContent* saveNode;
   if (parent->HasChildren()) {
     // XXX: We need to make sure that all of parent's
     //      children are in the text block.
 
     // If the parent has children, position the iterator
     // on the child that is to the left of the offset.
 
-    uint32_t childIndex = offset;
-
-    if (childIndex > 0) {
-      childIndex -= 1;
+    nsIContent* content = range->GetChildAtStartOffset();
+    if (content && parent->GetFirstChild() != content) {
+      content = content->GetPreviousSibling();
     }
-
-    nsIContent* content = parent->GetChildAt(childIndex);
     NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
     rv = iter->PositionAt(content);
     NS_ENSURE_SUCCESS(rv, rv);
 
     saveNode = content;
   } else {
     // The parent has no children, so position the iterator