Bug 596506 - Going to end of line using Ctrl-e on Mac positions caret after newline in textareas; r=bzbarsky a=blocking-final+
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 16 Sep 2010 14:40:26 -0400
changeset 54193 32b3aad80bb2073d36adf8cd4914aaaead97ce35
parent 54192 85bcddd5576ce60c097f3ecaa306a67f32fb8a0b
child 54194 e36e9e20741fffc7157a8e7cc95dabf554fa7048
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky, blocking-final
bugs596506
milestone2.0b7pre
Bug 596506 - Going to end of line using Ctrl-e on Mac positions caret after newline in textareas; r=bzbarsky a=blocking-final+
editor/libeditor/text/tests/Makefile.in
editor/libeditor/text/tests/test_bug596506.html
layout/generic/nsFrame.cpp
--- a/editor/libeditor/text/tests/Makefile.in
+++ b/editor/libeditor/text/tests/Makefile.in
@@ -44,16 +44,17 @@ relativesrcdir  = editor/libeditor/text/
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		test_bug471722.html \
 		test_bug569988.html \
 		test_bug590554.html \
 		test_bug596333.html \
+		test_bug596506.html \
 		$(NULL)
 
 # disables the key handling test on gtk2 because gtk2 overrides some key events
 # on our editor, and the combinations depend on the system.
 ifneq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 _TEST_FILES += \
 		test_texteditor_keyevent_handling.html \
 		$(NULL)
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/text/tests/test_bug596506.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=596506
+-->
+<head>
+  <title>Test for Bug 596506</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=596506">Mozilla Bug 596506</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 596506 **/
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTest);
+
+const kIsMac = navigator.platform.indexOf("Mac") == 0;
+
+function append(str) {
+  for (var i = 0; i < str.length; ++i) {
+    synthesizeKey(str[i], {});
+  }
+}
+
+function runTest() {
+  var edit = document.getElementById("edit");
+  edit.focus();
+
+  append("First");
+  synthesizeKey("VK_ENTER", {});
+  append("Second");
+  synthesizeKey("VK_UP", {});
+  synthesizeKey("VK_UP", {});
+  if (kIsMac) {
+    synthesizeKey("VK_RIGHT", {accelKey: true});
+  } else {
+    synthesizeKey("VK_END", {});
+  }
+  append("ly");
+  is(edit.value, "Firstly\nSecond",
+     "Pressing end should position the cursor before the terminating newline");
+  SimpleTest.finish();
+}
+
+</script>
+</pre>
+
+<textarea id="edit"></textarea>
+
+</body>
+</html>
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -5611,16 +5611,21 @@ nsIFrame::PeekOffset(nsPeekOffsetStruct*
       }
       if (!baseFrame)
         return NS_ERROR_FAILURE;
       FrameTarget targetFrame = DrillDownToSelectionFrame(baseFrame,
                                                           endOfLine);
       FrameContentRange range = GetRangeForFrame(targetFrame.frame);
       aPos->mResultContent = range.content;
       aPos->mContentOffset = endOfLine ? range.end : range.start;
+      if (endOfLine && targetFrame.frame->HasTerminalNewline()) {
+        // Do not position the caret after the terminating newline if we're
+        // trying to move to the end of line (see bug 596506)
+        --aPos->mContentOffset;
+      }
       aPos->mResultFrame = targetFrame.frame;
       aPos->mAttachForward = (aPos->mContentOffset == range.start);
       if (!range.content)
         return NS_ERROR_FAILURE;
       return NS_OK;
     }
 
     default: