| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style license that can be | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 /** | |
| 8 * @unrestricted | |
| 9 */ | |
| 10 Sources.JavaScriptOutlineDialog = class extends QuickOpen.FilteredListWidget.Pro
vider { | |
| 11 /** | |
| 12 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 13 * @param {function(number, number)} selectItemCallback | |
| 14 */ | |
| 15 constructor(uiSourceCode, selectItemCallback) { | |
| 16 super(); | |
| 17 | |
| 18 this._functionItems = []; | |
| 19 this._selectItemCallback = selectItemCallback; | |
| 20 Common.formatterWorkerPool.javaScriptOutline(uiSourceCode.workingCopy(), thi
s._didBuildOutlineChunk.bind(this)); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 25 * @param {function(number, number)} selectItemCallback | |
| 26 */ | |
| 27 static show(uiSourceCode, selectItemCallback) { | |
| 28 Sources.JavaScriptOutlineDialog._instanceForTests = | |
| 29 new Sources.JavaScriptOutlineDialog(uiSourceCode, selectItemCallback); | |
| 30 new QuickOpen.FilteredListWidget(Sources.JavaScriptOutlineDialog._instanceFo
rTests).showAsDialog(); | |
| 31 } | |
| 32 | |
| 33 /** | |
| 34 * @param {boolean} isLastChunk | |
| 35 * @param {!Array<!Common.FormatterWorkerPool.JSOutlineItem>} items | |
| 36 */ | |
| 37 _didBuildOutlineChunk(isLastChunk, items) { | |
| 38 this._functionItems.push(...items); | |
| 39 this.refresh(); | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * @override | |
| 44 * @return {number} | |
| 45 */ | |
| 46 itemCount() { | |
| 47 return this._functionItems.length; | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * @override | |
| 52 * @param {number} itemIndex | |
| 53 * @return {string} | |
| 54 */ | |
| 55 itemKeyAt(itemIndex) { | |
| 56 var item = this._functionItems[itemIndex]; | |
| 57 return item.name + (item.arguments ? item.arguments : ''); | |
| 58 } | |
| 59 | |
| 60 /** | |
| 61 * @override | |
| 62 * @param {number} itemIndex | |
| 63 * @param {string} query | |
| 64 * @return {number} | |
| 65 */ | |
| 66 itemScoreAt(itemIndex, query) { | |
| 67 var item = this._functionItems[itemIndex]; | |
| 68 var methodName = query.split('(')[0]; | |
| 69 if (methodName.toLowerCase() === item.name.toLowerCase()) | |
| 70 return 1 / (1 + item.line); | |
| 71 return -item.line - 1; | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * @override | |
| 76 * @param {number} itemIndex | |
| 77 * @param {string} query | |
| 78 * @param {!Element} titleElement | |
| 79 * @param {!Element} subtitleElement | |
| 80 */ | |
| 81 renderItem(itemIndex, query, titleElement, subtitleElement) { | |
| 82 var item = this._functionItems[itemIndex]; | |
| 83 titleElement.textContent = item.name + (item.arguments ? item.arguments : ''
); | |
| 84 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query); | |
| 85 subtitleElement.textContent = ':' + (item.line + 1); | |
| 86 } | |
| 87 | |
| 88 /** | |
| 89 * @override | |
| 90 * @param {?number} itemIndex | |
| 91 * @param {string} promptValue | |
| 92 */ | |
| 93 selectItem(itemIndex, promptValue) { | |
| 94 if (itemIndex === null) | |
| 95 return; | |
| 96 var lineNumber = this._functionItems[itemIndex].line; | |
| 97 if (!isNaN(lineNumber) && lineNumber >= 0) | |
| 98 this._selectItemCallback(lineNumber, this._functionItems[itemIndex].column
); | |
| 99 } | |
| 100 }; | |
| OLD | NEW |