Skip to content

Commit 0508192

Browse files
committed
Bug 1971094 - [devtools] Update search results when the selected source changes r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D253015
1 parent 0e3e3b3 commit 0508192

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

devtools/client/debugger/src/components/Editor/SearchInFileBar.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getIsCurrentThreadPaused,
1414
getSelectedSourceTextContent,
1515
getSearchOptions,
16-
getSelectedFrame,
1716
} from "../../selectors/index";
1817

1918
import { searchKeys } from "../../constants";
@@ -60,7 +59,6 @@ class SearchInFileBar extends Component {
6059
searchInFileEnabled: PropTypes.bool.isRequired,
6160
selectedSourceTextContent: PropTypes.object,
6261
selectedSource: PropTypes.object.isRequired,
63-
selectedFrame: PropTypes.object.isRequired,
6462
setActiveSearch: PropTypes.func.isRequired,
6563
querySearchWorker: PropTypes.func.isRequired,
6664
selectLocation: PropTypes.func.isRequired,
@@ -80,17 +78,20 @@ class SearchInFileBar extends Component {
8078
// FIXME: https://bugzilla.mozilla.org/show_bug.cgi?id=1774507
8179
UNSAFE_componentWillReceiveProps(nextProps) {
8280
const { query } = this.state;
83-
81+
// Trigger a search to update the search results ...
8482
if (
85-
query &&
86-
this.props.selectedSource &&
87-
this.props.searchInFileEnabled &&
88-
nextProps.selectedFrame &&
89-
// If a new source is selected update the file search results
90-
nextProps.selectedFrame.location.source.id !== nextProps.selectedSource.id
83+
// if there is a search query and ...
84+
(query &&
85+
// the file search bar is toggled open or ...
86+
((!this.props.searchInFileEnabled && nextProps.searchInFileEnabled) ||
87+
// a new source is selected.
88+
this.props.selectedSource.id !== nextProps.selectedSource.id)) ||
89+
// the source content changes
90+
this.props.selectedSourceTextContent !==
91+
nextProps.selectedSourceTextContent
9192
) {
92-
// Do not scroll to the search location, if we just switched a new source
93-
// and debugger is already paused on a selelcted line.
93+
// Do not scroll to the search location, if we just switched to a new source
94+
// and debugger is already paused on a selected line.
9495
this.doSearch(query, !nextProps.isPaused);
9596
}
9697
}
@@ -400,7 +401,6 @@ const mapStateToProps = state => {
400401
selectedSource: getSelectedSource(state),
401402
isPaused: getIsCurrentThreadPaused(state),
402403
selectedSourceTextContent: getSelectedSourceTextContent(state),
403-
selectedFrame: getSelectedFrame(state),
404404
modifiers: getSearchOptions(state, "file-search"),
405405
};
406406
};

devtools/client/debugger/test/mochitest/browser_dbg-search-file-retains-query.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

5-
// Tests the search bar retains previous query on re-opening.
6-
75
"use strict";
86

9-
add_task(async function () {
7+
// Tests the search bar retains previous query on re-opening.
8+
add_task(async function testSearchRetainsPreviousQuery() {
109
const dbg = await initDebugger("doc-scripts.html", "simple1.js");
1110
const {
1211
selectors: { getActiveSearch },
@@ -36,3 +35,54 @@ add_task(async function () {
3635
// Test for the retained query
3736
is(findElement(dbg, "fileSearchInput").value, "con");
3837
});
38+
39+
// Tests that the search results are updated when switching between sources
40+
add_task(async function testSearchUpdatesResultsOnSourceChanges() {
41+
const dbg = await initDebugger("doc-scripts.html", "simple1.js", "long.js");
42+
const {
43+
selectors: { getActiveSearch },
44+
} = dbg;
45+
46+
await selectSource(dbg, "simple1.js");
47+
48+
// Open search bar
49+
pressKey(dbg, "fileSearch");
50+
await waitFor(() => getActiveSearch() === "file");
51+
is(getActiveSearch(), "file");
52+
53+
// Type a search query
54+
const searchQuery = "this";
55+
type(dbg, searchQuery);
56+
await waitForSearchState(dbg);
57+
58+
await waitUntil(
59+
() => findElement(dbg, "fileSearchSummary").innerText !== "No results found"
60+
);
61+
62+
is(
63+
findElement(dbg, "fileSearchSummary").innerText,
64+
"1 of 3 results",
65+
`There are 3 results found for search query "${searchQuery}" in simple1.js`
66+
);
67+
is(
68+
findElement(dbg, "fileSearchInput").value,
69+
searchQuery,
70+
`The search input value matches the search query "${searchQuery}"`
71+
);
72+
73+
info("Switch to long.js");
74+
await selectSource(dbg, "long.js");
75+
76+
await waitUntil(
77+
() => findElement(dbg, "fileSearchSummary")?.innerText == "1 of 23 results"
78+
);
79+
ok(
80+
true,
81+
`There are 23 results found for search query "${searchQuery}" in long.js`
82+
);
83+
is(
84+
findElement(dbg, "fileSearchInput").value,
85+
searchQuery,
86+
`The search input value still matches the search query "${searchQuery}"`
87+
);
88+
});

devtools/client/debugger/test/mochitest/shared-head.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,7 @@ const selectors = {
19401940
sourceTreeFolderNode: ".sources-panel .node .folder",
19411941
excludePatternsInput: ".project-text-search .exclude-patterns-field input",
19421942
fileSearchInput: ".search-bar input",
1943+
fileSearchSummary: ".search-bar .search-field-summary",
19431944
watchExpressionsHeader: ".watch-expressions-pane ._header .header-label",
19441945
watchExpressionsAddButton: ".watch-expressions-pane ._header .plus",
19451946
editorNotificationFooter: ".editor-notification-footer",

0 commit comments

Comments
 (0)