Index: user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java	(revision 3663)
+++ user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java	(working copy)
@@ -45,6 +45,10 @@
   }
 
   public native void setSelectionRange(Element elem, int pos, int length) /*-{
-    elem.setSelectionRange(pos, pos + length);
+    try {
+      elem.setSelectionRange(pos, pos + length);
+    } catch (e) {
+      // Firefox throws exception if TextBox is not visible, even if attached
+    }
   }-*/;
 }
Index: user/src/com/google/gwt/user/client/ui/TextBoxBase.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/TextBoxBase.java	(revision 3663)
+++ user/src/com/google/gwt/user/client/ui/TextBoxBase.java	(working copy)
@@ -122,6 +122,9 @@
    */
   public String getSelectedText() {
     int start = getCursorPos(), length = getSelectionLength();
+    if (start < 0) {
+      return "";
+    }
     return getText().substring(start, start + length);
   }
 
@@ -179,7 +182,8 @@
   /**
    * Selects all of the text in the box.
    * 
-   * This will only work when the widget is attached to the document.
+   * This will only work when the widget is attached to the document and not
+   * hidden.
    */
   public void selectAll() {
     int length = getText().length();
@@ -191,6 +195,9 @@
   /**
    * Sets the cursor position.
    * 
+   * This will only work when the widget is attached to the document and not
+   * hidden.
+   * 
    * @param pos the new cursor position
    */
   public void setCursorPos(int pos) {
@@ -233,7 +240,8 @@
   /**
    * Sets the range of text to be selected.
    * 
-   * This will only work when the widget is attached to the document.
+   * This will only work when the widget is attached to the document and not
+   * hidden.
    * 
    * @param pos the position of the first character to be selected
    * @param length the number of characters to be selected
Index: user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java
===================================================================
--- user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java	(revision 3663)
+++ user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java	(working copy)
@@ -84,5 +84,13 @@
 
     // Check for setting 0;
     area.setSelectionRange(0, 0);
+
+    // Issue 1996: Cannot select text if TextBox is hidden
+    {
+      TextBoxBase area2 = createTextBoxBase();
+      area2.setVisible(false);
+      RootPanel.get().add(area2);
+      area.selectAll();
+    }
   }
 }
