OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 Sources.GoToLineDialog = class extends QuickOpen.FilteredListWidget.Delegate { | |
pfeldman
2017/02/07 02:10:03
Sources.GoToLineQuickOpen
einbinder
2017/02/28 23:59:07
Done.
| |
6 /** | |
7 * @override | |
8 * @param {?number} itemIndex | |
9 * @param {string} promptValue | |
10 */ | |
11 selectItem(itemIndex, promptValue) { | |
12 var uiSourceCode = this._currentUISourceCode(); | |
13 if (!uiSourceCode) | |
14 return; | |
15 var position = this._parsePosition(promptValue); | |
16 if (!position) | |
17 return; | |
18 Common.Revealer.reveal(uiSourceCode.uiLocation(position.line - 1, position.c olumn - 1)); | |
19 } | |
20 | |
21 /** | |
22 * @override | |
23 * @param {string} query | |
24 * @return {string} | |
25 */ | |
26 notFoundText(query) { | |
27 if (!this._currentUISourceCode()) | |
28 return Common.UIString('No file selected.'); | |
29 var position = this._parsePosition(query); | |
30 if (!position) | |
31 return Common.UIString('Type a number to go to that line.'); | |
32 var text = Common.UIString('Go to line ') + position.line; | |
33 if (position.column && position.column > 1) | |
34 text += Common.UIString(' and column ') + position.column; | |
35 text += '.'; | |
36 return text; | |
37 } | |
38 | |
39 /** | |
40 * @param {string} query | |
41 * @return {?{line: number, column: number}} | |
42 */ | |
43 _parsePosition(query) { | |
44 var parts = query.match(/([0-9]+)(\:[0-9]*)?/); | |
45 if (!parts || !parts[0] || parts[0].length !== query.length) | |
46 return null; | |
47 var line = parseInt(parts[1], 10); | |
48 var column; | |
49 if (parts[2]) | |
50 column = parseInt(parts[2].substring(1), 10); | |
51 return {line: Math.max(line | 0, 1), column: Math.max(column | 0, 1)}; | |
52 } | |
53 | |
54 /** | |
55 * @return {?Workspace.UISourceCode} | |
56 */ | |
57 _currentUISourceCode() { | |
58 var sourcesView = UI.context.flavor(Sources.SourcesView); | |
59 if (!sourcesView) | |
60 return null; | |
61 return sourcesView.currentUISourceCode(); | |
62 } | |
63 }; | |
OLD | NEW |