Files
react-native-devtools-frontend/front_end/sources/SearchSourcesView.js
T
Andres Olivares fd431fb765 [module.json extensions] sources views
Bug: 1134103
Change-Id: I1f050156edc6c0500aa19dc18f43d7463541128b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2584524
Commit-Queue: Andres Olivares <andoli@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-12-10 16:42:44 +00:00

84 lines
2.3 KiB
JavaScript

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Search from '../search/search.js';
import * as UI from '../ui/ui.js'; // eslint-disable-line no-unused-vars
import {SourcesSearchScope} from './SourcesSearchScope.js';
/** @type {!SearchSourcesView} */
let searchSourcesViewInstance;
export class SearchSourcesView extends Search.SearchView.SearchView {
/**
* @private
*/
constructor() {
super('sources');
}
static instance() {
if (!searchSourcesViewInstance) {
searchSourcesViewInstance = new SearchSourcesView();
}
return searchSourcesViewInstance;
}
/**
* @param {string} query
* @param {boolean=} searchImmediately
* @return {!Promise<!UI.Widget.Widget>}
*/
static async openSearch(query, searchImmediately) {
const view =
/** @type {!UI.View.View} */ (UI.ViewManager.ViewManager.instance().view('sources.search-sources-tab'));
// Deliberately use target location name so that it could be changed
// based on the setting later.
const location = /** @type {!UI.View.ViewLocation} */ (
/** @type {*} */ (await UI.ViewManager.ViewManager.instance().resolveLocation('drawer-view')));
location.appendView(view);
await UI.ViewManager.ViewManager.instance().revealView(/** @type {!UI.View.View} */ (view));
const widget = /** @type {!Search.SearchView.SearchView} */ (await view.widget());
widget.toggle(query, !!searchImmediately);
return widget;
}
/**
* @override
* @return {!Search.SearchConfig.SearchScope}
*/
createScope() {
return new SourcesSearchScope();
}
}
/**
* @implements {UI.ActionRegistration.ActionDelegate}
*/
export class ActionDelegate {
/**
* @override
* @param {!UI.Context.Context} context
* @param {string} actionId
* @return {boolean}
*/
handleAction(context, actionId) {
this._showSearch();
return true;
}
/**
* @return {!Promise<!UI.Widget.Widget>}
*/
_showSearch() {
const selection = UI.InspectorView.InspectorView.instance().element.window().getSelection();
let queryCandidate = '';
if (selection && selection.rangeCount) {
queryCandidate = selection.toString().replace(/\r?\n.*/, '');
}
return SearchSourcesView.openSearch(queryCandidate);
}
}