Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SearchSidebarPanel.js (242079 => 242080)
--- trunk/Source/WebInspectorUI/UserInterface/Views/SearchSidebarPanel.js 2019-02-26 08:11:37 UTC (rev 242079)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SearchSidebarPanel.js 2019-02-26 08:14:57 UTC (rev 242080)
@@ -100,11 +100,32 @@
if (!searchQuery.length)
return;
+ let promiseCount = 0;
+ let countPromise = async (promise, callback) => {
+ ++promiseCount;
+ if (promiseCount === 1) {
+ let searchingPlaceholder = WI.createMessageTextView("");
+ String.format(WI.UIString("Searching %s"), [(new WI.IndeterminateProgressSpinner).element], String.standardFormatters, searchingPlaceholder, (a, b) => {
+ a.append(b);
+ return a;
+ });
+ this.updateEmptyContentPlaceholder(searchingPlaceholder);
+ }
+
+ let value = await promise;
+
+ if (callback)
+ callback(value);
+
+ --promiseCount;
+ console.assert(promiseCount >= 0);
+ if (promiseCount === 0)
+ this.updateEmptyContentPlaceholder(WI.UIString("No Search Results"));
+ };
+
let isCaseSensitive = !!this._searchInputSettings.caseSensitive.value;
let isRegex = !!this._searchInputSettings.regularExpression.value;
- var updateEmptyContentPlaceholderTimeout = null;
-
function createTreeElementForMatchObject(matchObject, parentTreeElement)
{
let matchTreeElement = new WI.SearchResultTreeElement(matchObject);
@@ -116,23 +137,6 @@
matchTreeElement.revealAndSelect(false, true);
}
- function updateEmptyContentPlaceholderSoon()
- {
- if (updateEmptyContentPlaceholderTimeout)
- return;
- updateEmptyContentPlaceholderTimeout = setTimeout(updateEmptyContentPlaceholder.bind(this), 100);
- }
-
- function updateEmptyContentPlaceholder()
- {
- if (updateEmptyContentPlaceholderTimeout) {
- clearTimeout(updateEmptyContentPlaceholderTimeout);
- updateEmptyContentPlaceholderTimeout = null;
- }
-
- this.updateEmptyContentPlaceholder(WI.UIString("No Search Results"));
- }
-
function forEachMatch(searchQuery, lineContent, callback)
{
var lineMatch;
@@ -144,48 +148,36 @@
callback(lineMatch, searchRegex.lastIndex);
}
- function resourcesCallback(error, result)
- {
- updateEmptyContentPlaceholderSoon.call(this);
+ let resourceCallback = (frameId, url, {result}) => {
+ if (!result || !result.length)
+ return;
- if (error)
+ var frame = WI.networkManager.frameForIdentifier(frameId);
+ if (!frame)
return;
- function resourceCallback(frameId, url, error, resourceMatches)
- {
- updateEmptyContentPlaceholderSoon.call(this);
+ var resource = frame.url ="" url ? frame.mainResource : frame.resourceForURL(url);
+ if (!resource)
+ return;
- if (error || !resourceMatches || !resourceMatches.length)
- return;
+ var resourceTreeElement = this._searchTreeElementForResource(resource);
- var frame = WI.networkManager.frameForIdentifier(frameId);
- if (!frame)
- return;
+ for (var i = 0; i < result.length; ++i) {
+ var match = result[i];
+ forEachMatch(searchQuery, match.lineContent, (lineMatch, lastIndex) => {
+ var matchObject = new WI.SourceCodeSearchMatchObject(resource, match.lineContent, searchQuery, new WI.TextRange(match.lineNumber, lineMatch.index, match.lineNumber, lastIndex));
+ createTreeElementForMatchObject.call(this, matchObject, resourceTreeElement);
+ });
+ }
- var resource = frame.url ="" url ? frame.mainResource : frame.resourceForURL(url);
- if (!resource)
- return;
+ if (!resourceTreeElement.children.length)
+ this.contentTreeOutline.removeChild(resourceTreeElement);
+ };
- var resourceTreeElement = this._searchTreeElementForResource(resource);
-
- for (var i = 0; i < resourceMatches.length; ++i) {
- var match = resourceMatches[i];
- forEachMatch(searchQuery, match.lineContent, (lineMatch, lastIndex) => {
- var matchObject = new WI.SourceCodeSearchMatchObject(resource, match.lineContent, searchQuery, new WI.TextRange(match.lineNumber, lineMatch.index, match.lineNumber, lastIndex));
- createTreeElementForMatchObject.call(this, matchObject, resourceTreeElement);
- });
- }
-
- if (!resourceTreeElement.children.length)
- this.contentTreeOutline.removeChild(resourceTreeElement);
-
- updateEmptyContentPlaceholder.call(this);
- }
-
+ let resourcesCallback = ({result}) => {
let preventDuplicates = new Set;
- for (let i = 0; i < result.length; ++i) {
- let searchResult = result[i];
+ for (let searchResult of result) {
if (!searchResult.url || !searchResult.frameId)
continue;
@@ -198,7 +190,7 @@
preventDuplicates.add(key);
// COMPATIBILITY (iOS 9): Page.searchInResources did not have the optional requestId parameter.
- PageAgent.searchInResource(searchResult.frameId, searchResult.url, searchQuery, isCaseSensitive, isRegex, searchResult.requestId, resourceCallback.bind(this, searchResult.frameId, searchResult.url));
+ countPromise(PageAgent.searchInResource(searchResult.frameId, searchResult.url, searchQuery, isCaseSensitive, isRegex, searchResult.requestId), resourceCallback.bind(this, searchResult.frameId, searchResult.url));
}
let promises = [
@@ -206,47 +198,35 @@
WI.Target.awaitEvent(WI.Target.Event.ResourceAdded)
];
Promise.race(promises).then(this._contentChanged.bind(this));
- }
+ };
- function searchScripts(scriptsToSearch)
- {
- updateEmptyContentPlaceholderSoon.call(this);
-
- if (!scriptsToSearch.length)
+ let scriptCallback = (script, {result}) => {
+ if (!result || !result.length)
return;
- function scriptCallback(script, error, scriptMatches)
- {
- updateEmptyContentPlaceholderSoon.call(this);
+ var scriptTreeElement = this._searchTreeElementForScript(script);
- if (error || !scriptMatches || !scriptMatches.length)
- return;
+ for (let match of result) {
+ forEachMatch(searchQuery, match.lineContent, (lineMatch, lastIndex) => {
+ var matchObject = new WI.SourceCodeSearchMatchObject(script, match.lineContent, searchQuery, new WI.TextRange(match.lineNumber, lineMatch.index, match.lineNumber, lastIndex));
+ createTreeElementForMatchObject.call(this, matchObject, scriptTreeElement);
+ });
+ }
- var scriptTreeElement = this._searchTreeElementForScript(script);
+ if (!scriptTreeElement.children.length)
+ this.contentTreeOutline.removeChild(scriptTreeElement);
+ };
- for (var i = 0; i < scriptMatches.length; ++i) {
- var match = scriptMatches[i];
- forEachMatch(searchQuery, match.lineContent, (lineMatch, lastIndex) => {
- var matchObject = new WI.SourceCodeSearchMatchObject(script, match.lineContent, searchQuery, new WI.TextRange(match.lineNumber, lineMatch.index, match.lineNumber, lastIndex));
- createTreeElementForMatchObject.call(this, matchObject, scriptTreeElement);
- });
- }
+ let searchScripts = (scriptsToSearch) => {
+ if (!scriptsToSearch.length)
+ return;
- if (!scriptTreeElement.children.length)
- this.contentTreeOutline.removeChild(scriptTreeElement);
-
- updateEmptyContentPlaceholder.call(this);
- }
-
for (let script of scriptsToSearch)
- script.target.DebuggerAgent.searchInContent(script.id, searchQuery, isCaseSensitive, isRegex, scriptCallback.bind(this, script));
- }
+ countPromise(script.target.DebuggerAgent.searchInContent(script.id, searchQuery, isCaseSensitive, isRegex), scriptCallback.bind(this, script));
+ };
- function domCallback(error, searchId, resultsCount)
- {
- updateEmptyContentPlaceholderSoon.call(this);
-
- if (error || !resultsCount)
+ let domCallback = ({searchId, resultCount}) => {
+ if (!resultCount)
return;
console.assert(searchId);
@@ -253,19 +233,13 @@
this._domSearchIdentifier = searchId;
- function domSearchResults(error, nodeIds)
- {
- updateEmptyContentPlaceholderSoon.call(this);
-
- if (error)
+ let domSearchResults = ({nodeIds}) => {
+ // If someone started a new search, then return early and stop showing seach results from the old query.
+ if (this._domSearchIdentifier !== searchId)
return;
- for (var i = 0; i < nodeIds.length; ++i) {
- // If someone started a new search, then return early and stop showing seach results from the old query.
- if (this._domSearchIdentifier !== searchId)
- return;
-
- var domNode = WI.domManager.nodeForId(nodeIds[i]);
+ for (let nodeId of nodeIds) {
+ let domNode = WI.domManager.nodeForId(nodeId);
if (!domNode || !domNode.ownerDocument)
continue;
@@ -298,18 +272,17 @@
if (!resourceTreeElement.children.length)
this.contentTreeOutline.removeChild(resourceTreeElement);
- updateEmptyContentPlaceholder.call(this);
}
- }
+ };
- DOMAgent.getSearchResults(searchId, 0, resultsCount, domSearchResults.bind(this));
- }
+ countPromise(DOMAgent.getSearchResults(searchId, 0, resultCount), domSearchResults);
+ };
if (window.DOMAgent)
WI.domManager.ensureDocument();
if (window.PageAgent)
- PageAgent.searchInResources(searchQuery, isCaseSensitive, isRegex, resourcesCallback.bind(this));
+ countPromise(PageAgent.searchInResources(searchQuery, isCaseSensitive, isRegex), resourcesCallback);
setTimeout(searchScripts.bind(this, WI.debuggerManager.searchableScripts), 0);
@@ -319,13 +292,11 @@
this._domSearchIdentifier = undefined;
}
- DOMAgent.performSearch(searchQuery, domCallback.bind(this));
+ countPromise(DOMAgent.performSearch(searchQuery), domCallback);
}
// FIXME: Resource search should work in JSContext inspection.
// <https://webkit.org/b/131252> Web Inspector: JSContext inspection Resource search does not work
- if (!window.DOMAgent && !window.PageAgent)
- updateEmptyContentPlaceholderSoon.call(this);
}
// Private