Bug 1237236 - When collapsing the selection to the end of textframe that ends in a significant newline then set mHint to CARET_ASSOCIATE_AFTER so that the caret is rendered at the start of the next line if any. r=ehsan
authorMats Palmgren <mats@mozilla.com>
Thu, 17 Mar 2016 17:27:56 +0100
changeset 329093 f245074b4fb471b12024806bc476b1f5882348c4
parent 329092 ed56694589bed39601f0c5c09a1e676bc023db56
child 329094 b3b6173bf0318975bbd2b0d0ad55979d6b36a2f7
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
bugs1237236
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 1237236 - When collapsing the selection to the end of textframe that ends in a significant newline then set mHint to CARET_ASSOCIATE_AFTER so that the caret is rendered at the start of the next line if any. r=ehsan
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4931,16 +4931,26 @@ 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 && f->IsAtEndOfLine() && f->HasSignificantTerminalNewline()) {
+      if (f->GetContentEnd() == int32_t(aOffset)) {
+        mFrameSelection->SetHint(CARET_ASSOCIATE_AFTER);
+      }
+    }
+  }
+
   RefPtr<nsRange> range = new nsRange(&aParentNode);
   result = range->SetEnd(&aParentNode, aOffset);
   if (NS_FAILED(result)) {
     aRv.Throw(result);
     return;
   }
   result = range->SetStart(&aParentNode, aOffset);
   if (NS_FAILED(result)) {