bug 480262 - Deleting an auto-complete entry via shift+backspace(delete) removes last character from the entered text inside a textbox
authorNickolay Ponomarev <asqueella@gmail.com>
Sun, 30 Aug 2009 16:02:06 +0400
changeset 32086 c1972e85e27f1a3872c8df2b84f6d568cf28eb1f
parent 32085 fc2134fff83b22cfefd8082fab647473b6617898
child 32087 0ebc23cbbf14ec1e97e8d800104a7a685e068449
push id8839
push userasqueella@gmail.com
push dateSun, 30 Aug 2009 12:05:52 +0000
treeherderautoland@0ebc23cbbf14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs480262
milestone1.9.3a1pre
bug 480262 - Deleting an auto-complete entry via shift+backspace(delete) removes last character from the entered text inside a textbox Make the nsAutoCompleteController::HandleDelete() cancel the keypress event if it decides to delete an autocomplete entry. r=gavin
toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
toolkit/components/satchel/test/test_form_autocomplete.html
--- a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
@@ -552,16 +552,19 @@ nsAutoCompleteController::HandleDelete(P
 
   nsAutoString search;
   input->GetSearchParam(search);
 
   // Clear the row in our result and in the DB.
   result->RemoveValueAt(rowIndex, PR_TRUE);
   --mRowCount;
 
+  // We removed it, so make sure we cancel the event that triggered this call.
+  *_retval = PR_TRUE;
+
   // Unselect the current item.
   popup->SetSelectedIndex(-1);
 
   // Tell the tree that the row count changed.
   if (mTree)
     mTree->RowCountChanged(mRowCount, -1);
 
   // Adjust index, if needed.
@@ -574,19 +577,16 @@ nsAutoCompleteController::HandleDelete(P
 
     // Complete to the new current value.
     PRBool shouldComplete = PR_FALSE;
     mInput->GetCompleteDefaultIndex(&shouldComplete);
     if (shouldComplete) {
       nsAutoString value;
       if (NS_SUCCEEDED(GetResultValueAt(index, PR_TRUE, value))) {
         CompleteValue(value);
-      
-        // Make sure we cancel the event that triggered this call.
-        *_retval = PR_TRUE;
       }
     }
 
     // Invalidate the popup.
     popup->Invalidate();
   } else {
     // Nothing left in the popup, clear any pending search timers and
     // close the popup.
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -90,20 +90,25 @@ fh.addEntry("field4", "a\xe6");
 fh.addEntry("field4", "aa a\xe6");
 fh.addEntry("field4", "aba\xe6");
 fh.addEntry("field4", "bc d\xe6");
 fh.addEntry("field5", "1");
 fh.addEntry("field5", "12");
 fh.addEntry("field5", "123");
 fh.addEntry("field5", "1234");
 
+
+function setForm(value) {
+  input.value = value;
+  input.focus();
+}
+
 // Restore the form to the default state.
 function restoreForm() {
-    input.value = "";
-    input.focus();
+  setForm("");
 }
 
 // Check for expected form data.
 function checkForm(expectedValue) {
   var formID = input.parentNode.id;
   is(input.value, expectedValue, "Checking " + formID + " input");
 }
 
@@ -288,23 +293,32 @@ function runTest(testNum) {
         testNum = 49;
         break;
 
     /* Test removing entries from the dropdown */
 
     case 50:
         checkMenuEntries(["value1", "value2", "value3", "value4"]);
         // Delete the first entry (of 4)
+        setForm("value");
         doKey("down");
 
         // On OS X, shift-backspace and shift-delete work, just delete does not.
         // On Win/Linux, shift-backspace does not work, delete and shift-delete do.
-        doKey("delete", shiftModifier);
+        var osString = Components.classes["@mozilla.org/xre/app-info;1"].
+                       getService(Components.interfaces.nsIXULRuntime).OS;
+        if (osString == "Darwin")
+          doKey("back_space", shiftModifier);
+        else
+          doKey("delete", shiftModifier);
 
-        checkForm("");
+        // This tests that on OS X shift-backspace didn't delete the last character
+        // in the input (bug 480262).
+        checkForm("value");
+
         ok(!fh.entryExists("field1", "value1"), "checking that f1/v1 was deleted");
         doKey("return");
         checkForm("value2");
 
         // Trigger autocomplete popup
         restoreForm();
         doKey("down");
         break;