TextBoxImplIE6#getSelectionLength() uses some hacks to figure out how many /r/n appear in a TextArea, but the hack results in an infinite loop in a TextBox.  This patch uses the original implementaton TextBoxes, as they do not contain \r\n.

Patch by: jlabanca
Review by: jgw
Issue: 3822



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5741 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/TextArea.java b/user/src/com/google/gwt/user/client/ui/TextArea.java
index 03fb943..9d98856 100644
--- a/user/src/com/google/gwt/user/client/ui/TextArea.java
+++ b/user/src/com/google/gwt/user/client/ui/TextArea.java
@@ -103,7 +103,7 @@
 
   @Override
   public int getSelectionLength() {
-    return getImpl().getSelectionLength(getElement());
+    return getImpl().getTextAreaSelectionLength(getElement());
   }
 
   /**
diff --git a/user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java b/user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
index 2ebaac1..c58454e 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
@@ -44,6 +44,10 @@
     return getCursorPos(elem);
   }
 
+  public int getTextAreaSelectionLength(Element elem) {
+    return getSelectionLength(elem);
+  }
+
   public native void setSelectionRange(Element elem, int pos, int length) /*-{
     try {
       elem.setSelectionRange(pos, pos + length);
diff --git a/user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java b/user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java
index 83de886..f79aecc 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java
@@ -42,19 +42,7 @@
       var tr = elem.document.selection.createRange();
       if (tr.parentElement() !== elem)
         return 0;
-      var trLength = tr.text.length;
-
-      // Subtract characters from the end to account for trimmed newlines.
-      var offset = 0;
-      var tr2 = tr.duplicate();
-      tr2.moveEnd('character', -1);
-      var tr2Length = tr2.text.length;
-      while (tr2Length == trLength && tr2.parentElement() == elem && tr.compareEndPoints('StartToEnd', tr2) <= 0) {
-        offset += 2;
-        tr2.moveEnd('character', -1);
-        tr2Length = tr2.text.length;
-      }
-      return trLength + offset;
+      return tr.text.length;
     }
     catch (e) {
       return 0;
@@ -95,6 +83,31 @@
     }
   }-*/;
 
+  @Override
+  public native int getTextAreaSelectionLength(Element elem) /*-{
+    try {
+      var tr = elem.document.selection.createRange();
+      if (tr.parentElement() !== elem)
+        return 0;
+      var trLength = tr.text.length;
+
+      // Subtract characters from the end to account for trimmed newlines.
+      var offset = 0;
+      var tr2 = tr.duplicate();
+      tr2.moveEnd('character', -1);
+      var tr2Length = tr2.text.length;
+      while (tr2Length == trLength && tr2.parentElement() == elem && tr.compareEndPoints('StartToEnd', tr2) <= 0) {
+        offset += 2;
+        tr2.moveEnd('character', -1);
+        tr2Length = tr2.text.length;
+      }
+      return trLength + offset;
+    }
+    catch (e) {
+      return 0;
+    }
+  }-*/;
+
   /**
    * Moving the start 1 character will move across a \r\n, but \r\n counts as
    * two characters, so we need to offset the position accordingly.