Bug 963919 - When triggering file filtering via a keyboard shortcut, don't automatically fill the searchbox with the identifier under the caret position, r=past
authorVictor Porof <vporof@mozilla.com>
Tue, 28 Jan 2014 12:16:49 +0200
changeset 165558 e2aa30eb26497f779298ccb93e8db4b789b90e2c
parent 165481 fb5a3e3081deb64036611e24025919607dd5c4f0
child 165559 321d5443344db741b2dd325fa1241b187b426c8a
push id26097
push userryanvm@gmail.com
push dateTue, 28 Jan 2014 21:18:27 +0000
treeherdermozilla-central@128c86a925d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs963919
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963919 - When triggering file filtering via a keyboard shortcut, don't automatically fill the searchbox with the identifier under the caret position, r=past
browser/devtools/debugger/debugger-toolbar.js
browser/devtools/debugger/debugger-view.js
browser/devtools/debugger/test/browser.ini
browser/devtools/debugger/test/browser_dbg_search-autofill-identifier.js
browser/devtools/debugger/test/browser_dbg_search-function.js
--- a/browser/devtools/debugger/debugger-toolbar.js
+++ b/browser/devtools/debugger/debugger-toolbar.js
@@ -1066,31 +1066,37 @@ FilterView.prototype = {
    *        The operator to use for filtering.
    */
   _doSearch: function(aOperator = "", aText = "") {
     this._searchbox.focus();
     this._searchbox.value = ""; // Need to clear value beforehand. Bug 779738.
 
     if (aText) {
       this._searchbox.value = aOperator + aText;
+      return;
     }
-    else if (DebuggerView.editor.somethingSelected()) {
+    if (DebuggerView.editor.somethingSelected()) {
       this._searchbox.value = aOperator + DebuggerView.editor.getSelection();
+      return;
     }
-    else {
+    if (SEARCH_AUTOFILL.indexOf(aOperator) != -1) {
       let cursor = DebuggerView.editor.getCursor();
       let content = DebuggerView.editor.getText();
       let location = DebuggerView.Sources.selectedValue;
       let source = DebuggerController.Parser.get(content, location);
       let identifier = source.getIdentifierAt({ line: cursor.line+1, column: cursor.ch });
 
       if (identifier && identifier.name) {
         this._searchbox.value = aOperator + identifier.name;
+        this._searchbox.select();
+        this._searchbox.selectionStart += aOperator.length;
+        return;
       }
     }
+    this._searchbox.value = aOperator;
   },
 
   /**
    * Called when the source location filter key sequence was pressed.
    */
   _doFileSearch: function() {
     this._doSearch();
     this._searchboxHelpPanel.openPopup(this._searchbox);
--- a/browser/devtools/debugger/debugger-view.js
+++ b/browser/devtools/debugger/debugger-view.js
@@ -21,16 +21,17 @@ const GLOBAL_SEARCH_EXPAND_MAX_RESULTS =
 const GLOBAL_SEARCH_LINE_MAX_LENGTH = 300; // chars
 const GLOBAL_SEARCH_ACTION_MAX_DELAY = 1500; // ms
 const FUNCTION_SEARCH_ACTION_MAX_DELAY = 400; // ms
 const SEARCH_GLOBAL_FLAG = "!";
 const SEARCH_FUNCTION_FLAG = "@";
 const SEARCH_TOKEN_FLAG = "#";
 const SEARCH_LINE_FLAG = ":";
 const SEARCH_VARIABLE_FLAG = "*";
+const SEARCH_AUTOFILL = [SEARCH_GLOBAL_FLAG, SEARCH_FUNCTION_FLAG, SEARCH_TOKEN_FLAG];
 const EDITOR_VARIABLE_HOVER_DELAY = 350; // ms
 const EDITOR_VARIABLE_POPUP_POSITION = "topcenter bottomleft";
 const TOOLBAR_ORDER_POPUP_POSITION = "topcenter bottomleft";
 
 /**
  * Object defining the debugger view components.
  */
 let DebuggerView = {
--- a/browser/devtools/debugger/test/browser.ini
+++ b/browser/devtools/debugger/test/browser.ini
@@ -160,16 +160,17 @@ support-files =
 [browser_dbg_progress-listener-bug.js]
 [browser_dbg_reload-preferred-script-01.js]
 [browser_dbg_reload-preferred-script-02.js]
 [browser_dbg_reload-preferred-script-03.js]
 [browser_dbg_reload-same-script.js]
 [browser_dbg_scripts-switching-01.js]
 [browser_dbg_scripts-switching-02.js]
 [browser_dbg_scripts-switching-03.js]
+[browser_dbg_search-autofill-identifier.js]
 [browser_dbg_search-basic-01.js]
 [browser_dbg_search-basic-02.js]
 [browser_dbg_search-basic-03.js]
 [browser_dbg_search-basic-04.js]
 [browser_dbg_search-global-01.js]
 [browser_dbg_search-global-02.js]
 [browser_dbg_search-global-03.js]
 [browser_dbg_search-global-04.js]
@@ -242,15 +243,14 @@ support-files =
 [browser_dbg_variables-view-popup-07.js]
 [browser_dbg_variables-view-popup-08.js]
 [browser_dbg_variables-view-popup-09.js]
 [browser_dbg_variables-view-reexpand-01.js]
 [browser_dbg_variables-view-reexpand-02.js]
 [browser_dbg_variables-view-webidl.js]
 [browser_dbg_watch-expressions-01.js]
 [browser_dbg_watch-expressions-02.js]
-[browser_dbg_search-function.js]
 [browser_dbg_chrome-create.js]
 skip-if = os == "linux" # Bug 847558
 [browser_dbg_on-pause-raise.js]
 skip-if = os == "linux" # Bug 888811 & bug 891176
 [browser_dbg_break-on-dom-event.js]
 skip-if = os == "mac" # Bug 895426
rename from browser/devtools/debugger/test/browser_dbg_search-function.js
rename to browser/devtools/debugger/test/browser_dbg_search-autofill-identifier.js
--- a/browser/devtools/debugger/test/browser_dbg_search-function.js
+++ b/browser/devtools/debugger/test/browser_dbg_search-autofill-identifier.js
@@ -1,28 +1,135 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
- * Tests that Debugger Search uses the identifier under cursor
- * if nothing is selected or manually passed
+ * Tests that Debugger Search uses the identifier under cursor if nothing is
+ * selected or manually passed and searching using certain operators.
  */
-
 "use strict";
 
 function test() {
-
   const TAB_URL = EXAMPLE_URL + "doc_function-search.html";
 
   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     let Source = 'code_function-search-01.js';
     let Debugger = aPanel.panelWin;
     let Editor = Debugger.DebuggerView.editor;
     let Filtering = Debugger.DebuggerView.Filtering;
 
+    function doSearch(aOperator) {
+      Editor.dropSelection();
+      Filtering._doSearch(aOperator);
+    }
+
     waitForSourceShown(aPanel, Source).then(() => {
+      info("Testing with cursor at the beginning of the file...");
+
+      doSearch();
+      is(Filtering._searchbox.value, "",
+        "The searchbox value should not be auto-filled when searching for files.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("!");
+      is(Filtering._searchbox.value, "!",
+        "The searchbox value should not be auto-filled when searching across all files.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("@");
+      is(Filtering._searchbox.value, "@",
+        "The searchbox value should not be auto-filled when searching for functions.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("#");
+      is(Filtering._searchbox.value, "#",
+        "The searchbox value should not be auto-filled when searching inside a file.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch(":");
+      is(Filtering._searchbox.value, ":",
+        "The searchbox value should not be auto-filled when searching for a line.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("*");
+      is(Filtering._searchbox.value, "*",
+        "The searchbox value should not be auto-filled when searching for variables.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
       Editor.setCursor({ line: 7, ch: 0});
-      Filtering._doSearch("@");
-      is(Filtering._searchbox.value, "@test", "Searchbox value should be set to the identifier under cursor if no aText or selection provided");
+      info("Testing with cursor at line 8 and char 1...");
+
+      doSearch();
+      is(Filtering._searchbox.value, "",
+        "The searchbox value should not be auto-filled when searching for files.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("!");
+      is(Filtering._searchbox.value, "!test",
+        "The searchbox value was incorrect when searching across all files.");
+      is(Filtering._searchbox.selectionStart, 1,
+        "The searchbox operator should not be selected");
+      is(Filtering._searchbox.selectionEnd, 5,
+        "The searchbox contents should be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("@");
+      is(Filtering._searchbox.value, "@test",
+        "The searchbox value was incorrect when searching for functions.");
+      is(Filtering._searchbox.selectionStart, 1,
+        "The searchbox operator should not be selected");
+      is(Filtering._searchbox.selectionEnd, 5,
+        "The searchbox contents should be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("#");
+      is(Filtering._searchbox.value, "#test",
+        "The searchbox value should be auto-filled when searching inside a file.");
+      is(Filtering._searchbox.selectionStart, 1,
+        "The searchbox operator should not be selected");
+      is(Filtering._searchbox.selectionEnd, 5,
+        "The searchbox contents should be selected");
+      is(Editor.getSelection(), "test",
+        "The selection in the editor should be 'test'.");
+
+      doSearch(":");
+      is(Filtering._searchbox.value, ":",
+        "The searchbox value should not be auto-filled when searching for a line.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
+      doSearch("*");
+      is(Filtering._searchbox.value, "*",
+        "The searchbox value should not be auto-filled when searching for variables.");
+      is(Filtering._searchbox.selectionStart, Filtering._searchbox.selectionEnd,
+        "The searchbox contents should not be selected");
+      is(Editor.getSelection(), "",
+        "The selection in the editor should be empty.");
+
       closeDebuggerAndFinish(aPanel);
     });
   });
 };