Bug 1561583 - Search bar retains previous query on re-opening. r=davidwalsh
authorjanelledement <janelledement@gmail.com>
Wed, 14 Aug 2019 19:57:51 +0000
changeset 488028 640aff6b43b5099e362c4143f95068a188c5bcfa
parent 488027 45e0edd03be06954db7a715b8489beb601237048
child 488029 05b192f3ba82425d42ab63510b224a90334e5ca9
push id36434
push usercbrindusan@mozilla.com
push dateThu, 15 Aug 2019 09:44:30 +0000
treeherdermozilla-central@144fbfb409b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidwalsh
bugs1561583
milestone70.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 1561583 - Search bar retains previous query on re-opening. r=davidwalsh This patch allows the search bar to retain the previous query on re-opening. Differential Revision: https://phabricator.services.mozilla.com/D36664
devtools/client/debugger/src/components/Editor/SearchBar.js
devtools/client/debugger/test/mochitest/browser.ini
devtools/client/debugger/test/mochitest/browser_dbg-search-file-retains-query.js
devtools/client/debugger/test/mochitest/browser_dbg-search-file.js
--- a/devtools/client/debugger/src/components/Editor/SearchBar.js
+++ b/devtools/client/debugger/src/components/Editor/SearchBar.js
@@ -136,40 +136,40 @@ class SearchBar extends Component<Props,
   clearSearch = () => {
     const { editor: ed, query } = this.props;
     if (ed) {
       const ctx = { ed, cm: ed.codeMirror };
       removeOverlay(ctx, query);
     }
   };
 
-  closeSearch = (e: SyntheticEvent<HTMLElement>) => {
-    const { cx, closeFileSearch, editor, searchOn } = this.props;
+  closeSearch = (e: SyntheticKeyboardEvent<HTMLElement>) => {
+    const { cx, closeFileSearch, editor, searchOn, query } = this.props;
+    this.clearSearch();
     if (editor && searchOn) {
-      this.clearSearch();
       closeFileSearch(cx, editor);
       e.stopPropagation();
       e.preventDefault();
     }
-    this.setState({ query: "", inputFocused: false });
+    this.setState({ query, inputFocused: false });
   };
 
   toggleSearch = (e: SyntheticKeyboardEvent<HTMLElement>) => {
     e.stopPropagation();
     e.preventDefault();
     const { editor, searchOn, setActiveSearch } = this.props;
 
     // Set inputFocused to false, so that search query is highlighted whenever search shortcut is used, even if the input already has focus.
     this.setState({ inputFocused: false });
 
     if (!searchOn) {
       setActiveSearch("file");
     }
 
-    if (searchOn && editor) {
+    if (this.props.searchOn && editor) {
       const query = editor.codeMirror.getSelection() || this.state.query;
 
       if (query !== "") {
         this.setState({ query, inputFocused: true });
         this.doSearch(query);
       } else {
         this.setState({ query: "", inputFocused: true });
       }
--- a/devtools/client/debugger/test/mochitest/browser.ini
+++ b/devtools/client/debugger/test/mochitest/browser.ini
@@ -103,16 +103,18 @@ skip-if = os == "win"
 skip-if = os == "win"
 [browser_dbg-react-jsx.js]
 [browser_dbg-returnvalues.js]
 [browser_dbg-reload.js]
 [browser_dbg-reloading.js]
 skip-if = true
 [browser_dbg-pause-points.js]
 [browser_dbg-scopes-mutations.js]
+[browser_dbg-search-file-retains-query.js]
+skip-if = os == "win" # Bug 1393121
 [browser_dbg-search-file.js]
 skip-if = os == "win" # Bug 1393121
 [browser_dbg-search-file-paused.js]
 skip-if = os == "win" # Bug 1393121
 [browser_dbg-quick-open.js]
 skip-if = os == "win"
 [browser_dbg-search-project.js]
 [browser_dbg-blackbox-original.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-search-file-retains-query.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+// Tests the search bar retains previous query on re-opening.
+
+function waitForSearchState(dbg) {
+  return waitForState(dbg, () => getCM(dbg).state.search);
+}
+
+add_task(async function() {
+  const dbg = await initDebugger("doc-scripts.html", "simple1.js");
+  const {
+    selectors: { getActiveSearch, getFileSearchQuery },
+  } = dbg;
+  const source = findSource(dbg, "simple1.js");
+
+  await selectSource(dbg, source.url);
+
+  // Open search bar
+  pressKey(dbg, "fileSearch");
+  await waitFor(() => getActiveSearch() === "file");
+  is(getActiveSearch(), "file");
+
+  // Type a search query
+  type(dbg, "con");
+  await waitForSearchState(dbg);
+  is(getFileSearchQuery(), "con");
+  is(getCM(dbg).state.search.query, "con");
+
+  // Close the search bar
+  pressKey(dbg, "Escape");
+  await waitFor(() => getActiveSearch() === null);
+  is(getActiveSearch(), null);
+
+  // Re-open search bar
+  pressKey(dbg, "fileSearch");
+  await waitFor(() => getActiveSearch() === "file");
+  is(getActiveSearch(), "file");
+
+  // Test for the retained query
+  is(getCM(dbg).state.search.query, "con");
+  await waitForDispatch(dbg, "UPDATE_FILE_SEARCH_QUERY");
+  is(getFileSearchQuery(), "con");
+});
--- a/devtools/client/debugger/test/mochitest/browser_dbg-search-file.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-search-file.js
@@ -34,19 +34,20 @@ add_task(async function() {
   is(dbg.selectors.getActiveSearch(), null);
 
   pressKey(dbg, "fileSearch");
 
   const el = getFocusedEl(dbg);
 
   type(dbg, "con");
   await waitForSearchState(dbg);
+  await waitForDispatch(dbg, "UPDATE_SEARCH_RESULTS");
 
   const state = cm.state.search;
-
+  
   pressKey(dbg, "Enter");
   is(state.posFrom.line, 3);
 
   pressKey(dbg, "Enter");
   is(state.posFrom.line, 4);
 
   pressKey(dbg, "ShiftEnter");
   is(state.posFrom.line, 3);
@@ -70,9 +71,10 @@ add_task(async function() {
   await selectSource(dbg, "simple2");
   ok(findElement(dbg, "searchField"), "Search field is still visible");
 
   // search is always focused regardless of when or how it was opened
   pressKey(dbg, "fileSearch");
   await clickElement(dbg, "codeMirror");
   pressKey(dbg, "fileSearch");
   is(dbg.win.document.activeElement.tagName, "INPUT", "Search field focused");
+  
 });