Bug 1259949 - Set the CARET_ASSOCIATE_AFTER hint also when we collapse just after a text node that ends with a significant newline. r=ehsan
authorMats Palmgren <mats@mozilla.com>
Fri, 01 Apr 2016 02:08:15 +0200
changeset 330926 2e97b6bf18de0d88acfe70eb96a04b097e8d436c
parent 330925 b2d35c87d6cddeea7f88e5bc4a7bccebd3100fce
child 330927 74f7a5eba75e2364785703d46d3dae6c9f8e5af9
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1259949, 1258308
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1259949 - Set the CARET_ASSOCIATE_AFTER hint also when we collapse just after a text node that ends with a significant newline. r=ehsan nsCaret::GetFrameAndOffset may return a text frame also when aParentNode is the container of a text node and aOffset is just after it. In this case we also want CARET_ASSOCIATE_AFTER if the text ends with a significant newline. (follow-up from bug 1258308)
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4932,25 +4932,27 @@ Selection::Collapse(nsINode& aParentNode
 
   // Delete all of the current ranges
   Clear(presContext);
 
   // Turn off signal for table selection
   mFrameSelection->ClearTableCellSelection();
 
   // Hack to display the caret on the right line (bug 1237236).
-  if (aParentNode.IsContent()) {
-    nsTextFrame* f = do_QueryFrame(aParentNode.AsContent()->GetPrimaryFrame());
-    if (f) {
-      int32_t frameOffset;
-      f = do_QueryFrame(nsCaret::GetFrameAndOffset(this, &aParentNode,
-                                                   aOffset, &frameOffset));
-    }
+  if (mFrameSelection->GetHint() != CARET_ASSOCIATE_AFTER &&
+      aParentNode.IsContent()) {
+    int32_t frameOffset;
+    nsTextFrame* f =
+      do_QueryFrame(nsCaret::GetFrameAndOffset(this, &aParentNode,
+                                               aOffset, &frameOffset));
     if (f && f->IsAtEndOfLine() && f->HasSignificantTerminalNewline()) {
-      if (f->GetContentEnd() == int32_t(aOffset)) {
+      if ((aParentNode.AsContent() == f->GetContent() &&
+           f->GetContentEnd() == int32_t(aOffset)) ||
+          (&aParentNode == f->GetContent()->GetParentNode() &&
+           aParentNode.IndexOf(f->GetContent()) + 1 == int32_t(aOffset))) {
         mFrameSelection->SetHint(CARET_ASSOCIATE_AFTER);
       }
     }
   }
 
   RefPtr<nsRange> range = new nsRange(&aParentNode);
   result = range->SetEnd(&aParentNode, aOffset);
   if (NS_FAILED(result)) {