From ed8443d555c33d16b0ba0c78becc8feec3853269 Mon Sep 17 00:00:00 2001 From: yulia Date: Mon, 26 Aug 2019 18:38:01 +0000 Subject: [PATCH] Bug 1575237 - Initial implementation of search for top level documents in the inspector; r=pbro Differential Revision: https://phabricator.services.mozilla.com/D42662 --HG-- extra : moz-landing-system : lando --- devtools/client/inspector/inspector-search.js | 76 +++++++++++-------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/devtools/client/inspector/inspector-search.js b/devtools/client/inspector/inspector-search.js index 6ad6df98cb91..95819c63cf9a 100644 --- a/devtools/client/inspector/inspector-search.js +++ b/devtools/client/inspector/inspector-search.js @@ -481,7 +481,7 @@ SelectorAutocompleter.prototype = { * Suggests classes,ids and tags based on the user input as user types in the * searchbox. */ - showSuggestions: function() { + showSuggestions: async function() { let query = this.searchBox.value; const state = this.state; let firstPart = ""; @@ -514,37 +514,51 @@ SelectorAutocompleter.prototype = { query += "*"; } - const suggestionsPromise = this.walker.getSuggestionsForQuery( - query, - firstPart, - state - ); - this._lastQuery = suggestionsPromise.then(result => { - this.emit("processing-done"); - if (result.query !== query) { - // This means that this response is for a previous request and the user - // as since typed something extra leading to a new request. - return promise.resolve(null); - } + const inspectorFront = this.inspector.inspectorFront; + const remoteInspectors = await inspectorFront.getChildInspectors(); + const inspectors = [inspectorFront, ...remoteInspectors]; - if (state === this.States.CLASS) { - firstPart = "." + firstPart; - } else if (state === this.States.ID) { - firstPart = "#" + firstPart; - } - - // If there is a single tag match and it's what the user typed, then - // don't need to show a popup. - if ( - result.suggestions.length === 1 && - result.suggestions[0][0] === firstPart - ) { - result.suggestions = []; - } - - // Wait for the autocomplete-popup to fire its popup-opened event, to make sure - // the autoSelect item has been selected. - return this._showPopup(result.suggestions, state); + const suggestionsPromises = inspectors.map(async inspector => { + const walker = inspector.walker; + return walker.getSuggestionsForQuery(query, firstPart, state); }); + + this._lastQuery = Promise.all(suggestionsPromises) + .then(suggestions => { + // Merge all the results + const result = { query: "", suggestions: [] }; + for (const r of suggestions) { + result.query = r.query; + result.suggestions = result.suggestions.concat(r.suggestions); + } + return result; + }) + .then(result => { + this.emit("processing-done"); + if (result.query !== query) { + // This means that this response is for a previous request and the user + // as since typed something extra leading to a new request. + return promise.resolve(null); + } + + if (state === this.States.CLASS) { + firstPart = "." + firstPart; + } else if (state === this.States.ID) { + firstPart = "#" + firstPart; + } + + // If there is a single tag match and it's what the user typed, then + // don't need to show a popup. + if ( + result.suggestions.length === 1 && + result.suggestions[0][0] === firstPart + ) { + result.suggestions = []; + } + + // Wait for the autocomplete-popup to fire its popup-opened event, to make sure + // the autoSelect item has been selected. + return this._showPopup(result.suggestions, state); + }); }, };