Bug 612271 - Cursor jumps back to the end of the previous line after pressing enter at the end of a textarea managed by the jQuery autoResize plugin; r=roc a=blocking-betaN+
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 07 Dec 2010 01:30:05 -0500
changeset 58903 1655a76ea1880f530086c48b21f80ef93d190629
parent 58902 56a617969b41e15e1e811a508239ec0a2944565e
child 58904 19b83d59edbfcb6a5e40b91ce081731e7454804c
push idunknown
push userunknown
push dateunknown
reviewersroc, blocking-betaN
bugs612271
milestone2.0b8pre
Bug 612271 - Cursor jumps back to the end of the previous line after pressing enter at the end of a textarea managed by the jQuery autoResize plugin; r=roc a=blocking-betaN+
layout/base/tests/Makefile.in
layout/base/tests/bug612271-1.html
layout/base/tests/bug612271-2.html
layout/base/tests/bug612271-3.html
layout/base/tests/bug612271-ref.html
layout/base/tests/test_reftests_with_caret.html
layout/forms/nsTextControlFrame.cpp
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -117,16 +117,20 @@ DEFINES += -D_IMPL_NS_LAYOUT
 		     bug602141-1.html \
 		     bug602141-1-ref.html \
 		     bug602141-2.html \
 		     bug602141-2-ref.html \
 		     bug602141-3.html \
 		     bug602141-3-ref.html \
 		     bug602141-4.html \
 		     bug602141-4-ref.html \
+		     bug612271-1.html \
+		     bug612271-2.html \
+		     bug612271-3.html \
+		     bug612271-ref.html \
 		     bug613433-1.html \
 		     bug613433-2.html \
 		     bug613433-3.html \
 		     bug613433-ref.html \
 		     bug613807-1.html \
 		     bug613807-1-ref.html \
 		test_bug514127.html \
 		test_bug518777.html \
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/bug612271-1.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML><html><head>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+ <textarea id="target" style="height: 100px"
+    onkeydown="this.style.display='block';this.style.height='200px';">foo</textarea>
+<script>
+  var t = document.querySelector("textarea");
+  t.focus();
+  sendKey('ENTER', "target");
+  document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd));
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/bug612271-2.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML><html><head>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+  <textarea id="target" style="height: 100px"
+    onkeypress="this.style.display='block';this.style.height='200px';">foo</textarea>
+<script>
+  var t = document.querySelector("textarea");
+  t.focus();
+  sendKey('ENTER', "target");
+  document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd));
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/bug612271-3.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML><html><head>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+  <textarea id="target" style="height: 100px"
+    onkeyup="this.style.display='block';this.style.height='200px';">foo</textarea>
+<script>
+  var t = document.querySelector("textarea");
+  t.focus();
+  sendKey('ENTER', "target");
+  document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd));
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/bug612271-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML><html><head>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+  <textarea autofocus style="height: 200px; display: block;"
+    >foo
+</textarea>
+  4 - 4
+</body>
+</html>
--- a/layout/base/tests/test_reftests_with_caret.html
+++ b/layout/base/tests/test_reftests_with_caret.html
@@ -97,16 +97,19 @@ var tests = [
     [ 'bug512295-1.html' , 'bug512295-1-ref.html' ] ,
     [ 'bug512295-2.html' , 'bug512295-2-ref.html' ] ,
     [ 'bug585922.html'   , 'bug585922-ref.html'   ] ,
     [ 'bug597519-1.html' , 'bug597519-1-ref.html' ] ,
     [ 'bug602141-1.html' , 'bug602141-1-ref.html' ] ,
     [ 'bug602141-2.html' , 'bug602141-2-ref.html' ] ,
     [ 'bug602141-3.html' , 'bug602141-3-ref.html' ] ,
     [ 'bug602141-4.html' , 'bug602141-4-ref.html' ] ,
+    [ 'bug612271-1.html' , 'bug612271-ref.html' ] ,
+    [ 'bug612271-2.html' , 'bug612271-ref.html' ] ,
+    [ 'bug612271-3.html' , 'bug612271-ref.html' ] ,
     [ 'bug613433-1.html' , 'bug613433-ref.html' ] ,
     [ 'bug613433-2.html' , 'bug613433-ref.html' ] ,
     [ 'bug613433-3.html' , 'bug613433-ref.html' ] ,
     [ 'bug613807-1.html' , 'bug613807-1-ref.html' ]
 ];
 var testIndex = 0;
 
 function nextTest() {
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -1087,18 +1087,28 @@ nsTextControlFrame::OffsetToDOMPoint(PRI
   rv = nodeList->Item(0, getter_AddRefs(firstNode));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(firstNode);
 
   if (length == 0 || aOffset < 0) {
     NS_IF_ADDREF(*aResult = rootNode);
     *aPosition = 0;
   } else if (textNode) {
-    NS_IF_ADDREF(*aResult = firstNode);
-    *aPosition = aOffset;
+    PRUint32 textLength = 0;
+    textNode->GetLength(&textLength);
+    if (length == 2 && PRUint32(aOffset) == textLength) {
+      // If we're at the end of the text node and we have a trailing BR node,
+      // set the selection on the BR node.
+      NS_IF_ADDREF(*aResult = rootNode);
+      *aPosition = 1;
+    } else {
+      // Otherwise, set the selection on the textnode itself.
+      NS_IF_ADDREF(*aResult = firstNode);
+      *aPosition = aOffset;
+    }
   } else {
     NS_IF_ADDREF(*aResult = rootNode);
     *aPosition = 0;
   }
 
   return NS_OK;
 }