Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(724)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sources/OutlineQuickOpen.js

Issue 2783233005: DevTools: Move JavaScript and CSS outline into QuickOpen (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sources/OutlineQuickOpen.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sources/OutlineQuickOpen.js b/third_party/WebKit/Source/devtools/front_end/sources/OutlineQuickOpen.js
new file mode 100644
index 0000000000000000000000000000000000000000..90688271798789eced4b42ff05379bb64e28a258
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/sources/OutlineQuickOpen.js
@@ -0,0 +1,123 @@
+// Copyright 2017 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.
+
+/**
+ * @unrestricted
+ */
+Sources.OutlineQuickOpen = class extends QuickOpen.FilteredListWidget.Provider {
+ constructor() {
+ super();
+ this._items = [];
+ this._active = false;
+ }
+
+ /**
+ * @override
+ */
+ attach() {
+ this._items = [];
+ this._active = false;
+
+ var uiSourceCode = this._currentUISourceCode();
+ if (uiSourceCode) {
+ this._active = Common.formatterWorkerPool.outlineForMimetype(
+ uiSourceCode.workingCopy(), uiSourceCode.contentType().canonicalMimeType(),
+ this._didBuildOutlineChunk.bind(this));
+ }
+ }
+
+ /**
+ * @param {boolean} isLastChunk
+ * @param {!Array<!Common.FormatterWorkerPool.OutlineItem>} items
+ */
+ _didBuildOutlineChunk(isLastChunk, items) {
+ this._items.push(...items);
+ this.refresh();
+ }
+
+ /**
+ * @override
+ * @return {number}
+ */
+ itemCount() {
+ return this._items.length;
+ }
+
+ /**
+ * @override
+ * @param {number} itemIndex
+ * @return {string}
+ */
+ itemKeyAt(itemIndex) {
+ var item = this._items[itemIndex];
+ return item.title + (item.subtitle ? item.subtitle : '');
+ }
+
+ /**
+ * @override
+ * @param {number} itemIndex
+ * @param {string} query
+ * @return {number}
+ */
+ itemScoreAt(itemIndex, query) {
+ var item = this._items[itemIndex];
+ var methodName = query.split('(')[0];
+ if (methodName.toLowerCase() === item.title.toLowerCase())
+ return 1 / (1 + item.line);
+ return -item.line - 1;
+ }
+
+ /**
+ * @override
+ * @param {number} itemIndex
+ * @param {string} query
+ * @param {!Element} titleElement
+ * @param {!Element} subtitleElement
+ */
+ renderItem(itemIndex, query, titleElement, subtitleElement) {
+ var item = this._items[itemIndex];
+ titleElement.textContent = item.title + (item.subtitle ? item.subtitle : '');
+ QuickOpen.FilteredListWidget.highlightRanges(titleElement, query);
+ subtitleElement.textContent = ':' + (item.line + 1);
+ }
+
+ /**
+ * @override
+ * @param {?number} itemIndex
+ * @param {string} promptValue
+ */
+ selectItem(itemIndex, promptValue) {
+ if (itemIndex === null)
+ return;
+ var uiSourceCode = this._currentUISourceCode();
+ if (!uiSourceCode)
+ return;
+ var lineNumber = this._items[itemIndex].line;
+ if (!isNaN(lineNumber) && lineNumber >= 0)
+ Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, this._items[itemIndex].column));
+ }
+
+
+ /**
+ * @return {?Workspace.UISourceCode}
+ */
+ _currentUISourceCode() {
+ var sourcesView = UI.context.flavor(Sources.SourcesView);
+ if (!sourcesView)
+ return null;
+ return sourcesView.currentUISourceCode();
+ }
+
+ /**
+ * @override
+ * @return {string}
+ */
+ notFoundText() {
+ if (!this._currentUISourceCode())
+ return Common.UIString('No file selected.');
+ if (!this._active)
+ return Common.UIString('Open a JavaScript or CSS file to see symbols');
+ return Common.UIString('No results found');
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698