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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
janelledement 2019-08-14 19:57:51 +00:00
Родитель 87723c635c
Коммит b26b2d5fcc
4 изменённых файлов: 55 добавлений и 6 удалений

Просмотреть файл

@ -141,15 +141,15 @@ class SearchBar extends Component<Props, State> {
}
};
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>) => {
@ -164,7 +164,7 @@ class SearchBar extends Component<Props, State> {
setActiveSearch("file");
}
if (searchOn && editor) {
if (this.props.searchOn && editor) {
const query = editor.codeMirror.getSelection() || this.state.query;
if (query !== "") {

Просмотреть файл

@ -108,6 +108,8 @@ skip-if = os == "win"
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]

Просмотреть файл

@ -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");
});

Просмотреть файл

@ -39,9 +39,10 @@ add_task(async function() {
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);
@ -75,4 +76,5 @@ add_task(async function() {
await clickElement(dbg, "codeMirror");
pressKey(dbg, "fileSearch");
is(dbg.win.document.activeElement.tagName, "INPUT", "Search field focused");
});