Bug 240933 - Part 4: Remove the code responsible for handling non-preformatted text in WillInsertText; r=roc a=dbaron
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 16 Jul 2010 17:34:59 -0400
changeset 53726 5c877925d6f53d822648e735ad12f14cb94743fa
parent 53725 3d1067e0318fd59444aaef33b4b27ecc03eaeb14
child 53727 5c29a10e30065433853b5f1f4696c73052bf5eac
push idunknown
push userunknown
push dateunknown
reviewersroc, dbaron
bugs240933
milestone2.0b6pre
Bug 240933 - Part 4: Remove the code responsible for handling non-preformatted text in WillInsertText; r=roc a=dbaron
editor/libeditor/text/nsTextEditRules.cpp
editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -743,80 +743,22 @@ nsTextEditRules::WillInsertText(PRInt32 
     NS_ENSURE_SUCCESS(res, res);
   }
   else // aAction == kInsertText
   {
     // find where we are
     nsCOMPtr<nsIDOMNode> curNode = selNode;
     PRInt32 curOffset = selOffset;
 
-    // is our text going to be PREformatted?  
-    // We remember this so that we know how to handle tabs.
-    PRBool isPRE;
-    res = mEditor->IsPreformatted(selNode, &isPRE);
-    NS_ENSURE_SUCCESS(res, res);    
-
     // don't spaz my selection in subtransactions
     nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
 
-    if (isPRE)
-    {
-      res = mEditor->InsertTextImpl(*outString, address_of(curNode),
-                                    &curOffset, doc);
-      NS_ENSURE_SUCCESS(res, res);
-    }
-    else
-    {
-      const nsString& tString = PromiseFlatString(*outString);
-      const PRUnichar *unicodeBuf = tString.get();
-      nsCOMPtr<nsIDOMNode> unused;
-      PRInt32 pos = 0;
-
-      char specialChars[] = {TAB, nsCRT::LF, 0};
-      while (unicodeBuf && (pos != -1) && ((PRUint32)pos < tString.Length()))
-      {
-        PRInt32 oldPos = pos;
-        PRInt32 subStrLen;
-        pos = tString.FindCharInSet(specialChars, oldPos);
-        
-        if (pos != -1) 
-        {
-          subStrLen = pos - oldPos;
-          // if first char is newline, then use just it
-          if (subStrLen == 0)
-            subStrLen = 1;
-        }
-        else
-        {
-          subStrLen = tString.Length() - oldPos;
-          pos = tString.Length();
-        }
-
-        nsDependentSubstring subStr(tString, oldPos, subStrLen);
-        
-        // is it a tab?
-        if (subStr.EqualsLiteral("\t"))
-        {
-          res = mEditor->InsertTextImpl(NS_LITERAL_STRING("    "), address_of(curNode), &curOffset, doc);
-          pos++;
-        }
-        // is it a return?
-        else if (subStr.EqualsLiteral(LFSTR))
-        {
-          res = mEditor->CreateBRImpl(address_of(curNode), &curOffset, address_of(unused), nsIEditor::eNone);
-          pos++;
-        }
-        else
-        {
-          res = mEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc);
-        }
-        NS_ENSURE_SUCCESS(res, res);
-      }
-      outString->Assign(tString);
-    }
+    res = mEditor->InsertTextImpl(*outString, address_of(curNode),
+                                  &curOffset, doc);
+    NS_ENSURE_SUCCESS(res, res);
 
     if (curNode) 
     {
       // Make the caret attach to the inserted text, unless this text ends with a LF, 
       // in which case make the caret attach to the next line.
       PRBool endsWithLF =
         !outString->IsEmpty() && outString->Last() == nsCRT::LF;
       nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
--- a/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
+++ b/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
@@ -287,16 +287,28 @@ function runTests()
     synthesizeKey("VK_TAB", { });
     check(aDescription + "Tab",
           true, true, !aIsTabbable && !aIsReadonly);
     is(aElement.value, !aIsTabbable && !aIsReadonly ? "a\t" : "a",
        aDescription + "Tab");
     is(fm.focusedElement, aElement,
        aDescription + "focus moved unexpectedly (Tab)");
 
+    // If the editor is not tabbable, make sure that it accepts tab characters
+    // even if it's empty.
+    if (!aIsTabbable && !aIsReadonly) {
+      reset("");
+      synthesizeKey("VK_TAB", {});
+      check(aDescription + "Tab on empty textarea",
+            true, true, !aIsReadonly);
+      is(aElement.value, "\t", aDescription + "Tab on empty textarea");
+      is(fm.focusedElement, aElement,
+         aDescription + "focus moved unexpectedly (Tab on empty textarea");
+    }
+
     reset("a");
     synthesizeKey("VK_TAB", { shiftKey: true });
     check(aDescription + "Shift+Tab", true, true, false);
     is(aElement.value, "a", aDescription + "Shift+Tab");
     is(fm.focusedElement, aElement,
        aDescription + "focus moved unexpectedly (Shift+Tab)");
 
     // Ctrl+Tab may be consumed by tabbrowser but editor shouldn't consume this.