OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * [SearchText] represent the search field text. The text is viewed in three | 6 * [SearchText] represent the search field text. The text is viewed in three |
7 * ways: [text] holds the original search text, used for performing | 7 * ways: [text] holds the original search text, used for performing |
8 * case-sensitive matches, [lowerCase] holds the lower-case search text, used | 8 * case-sensitive matches, [lowerCase] holds the lower-case search text, used |
9 * for performing case-insenstive matches, [camelCase] holds a camel-case | 9 * for performing case-insenstive matches, [camelCase] holds a camel-case |
10 * interpretation of the search text, used to order matches in camel-case. | 10 * interpretation of the search text, used to order matches in camel-case. |
11 */ | 11 */ |
12 class SearchText { | 12 class SearchText { |
13 final String text; | 13 final String text; |
14 final String lowerCase; | 14 final String lowerCase; |
15 final String camelCase; | 15 final String camelCase; |
16 | 16 |
17 SearchText(String searchText) | 17 SearchText(String searchText) |
18 : text = searchText, | 18 : text = searchText, |
19 lowerCase = searchText.toLowerCase(), | 19 lowerCase = searchText.toLowerCase(), |
20 camelCase = searchText.isEmpty() ? '' | 20 camelCase = searchText.isEmpty() ? '' |
21 : '${searchText.substring(0, 1).toUpperCase()}' | 21 : '${searchText.substring(0, 1).toUpperCase()}' |
22 '${searchText.substring(1)}'; | 22 '${searchText.substring(1)}'; |
23 | 23 |
24 int get length() => text.length; | 24 int get length => text.length; |
25 | 25 |
26 bool isEmpty() => length == 0; | 26 bool isEmpty() => length == 0; |
27 } | 27 } |
28 | 28 |
29 /** | 29 /** |
30 * [StringMatch] represents the case-insensitive matching of [searchText] as a | 30 * [StringMatch] represents the case-insensitive matching of [searchText] as a |
31 * substring within a [text]. | 31 * substring within a [text]. |
32 */ | 32 */ |
33 class StringMatch { | 33 class StringMatch { |
34 final SearchText searchText; | 34 final SearchText searchText; |
35 final String text; | 35 final String text; |
36 final int matchOffset; | 36 final int matchOffset; |
37 final int matchEnd; | 37 final int matchEnd; |
38 | 38 |
39 StringMatch(this.searchText, | 39 StringMatch(this.searchText, |
40 this.text, this.matchOffset, this.matchEnd); | 40 this.text, this.matchOffset, this.matchEnd); |
41 | 41 |
42 /** | 42 /** |
43 * Returns the HTML representation of the match. | 43 * Returns the HTML representation of the match. |
44 */ | 44 */ |
45 String toHtml() { | 45 String toHtml() { |
46 return '${text.substring(0, matchOffset)}' | 46 return '${text.substring(0, matchOffset)}' |
47 '<span class="drop-down-link-highlight">$matchText</span>' | 47 '<span class="drop-down-link-highlight">$matchText</span>' |
48 '${text.substring(matchEnd)}'; | 48 '${text.substring(matchEnd)}'; |
49 } | 49 } |
50 | 50 |
51 String get matchText() => | 51 String get matchText => |
52 text.substring(matchOffset, matchEnd); | 52 text.substring(matchOffset, matchEnd); |
53 | 53 |
54 /** | 54 /** |
55 * Is [:true:] iff [searchText] matches the full [text] case-sensitively. | 55 * Is [:true:] iff [searchText] matches the full [text] case-sensitively. |
56 */ | 56 */ |
57 bool get isFullMatch() => text == searchText.text; | 57 bool get isFullMatch => text == searchText.text; |
58 | 58 |
59 /** | 59 /** |
60 * Is [:true:] iff [searchText] matches a substring of [text] | 60 * Is [:true:] iff [searchText] matches a substring of [text] |
61 * case-sensitively. | 61 * case-sensitively. |
62 */ | 62 */ |
63 bool get isExactMatch() => matchText == searchText.text; | 63 bool get isExactMatch => matchText == searchText.text; |
64 | 64 |
65 /** | 65 /** |
66 * Is [:true:] iff [searchText] matches a substring of [text] when | 66 * Is [:true:] iff [searchText] matches a substring of [text] when |
67 * [searchText] is interpreted as camel case. | 67 * [searchText] is interpreted as camel case. |
68 */ | 68 */ |
69 bool get isCamelCaseMatch() => matchText == searchText.camelCase; | 69 bool get isCamelCaseMatch => matchText == searchText.camelCase; |
70 } | 70 } |
71 | 71 |
72 /** | 72 /** |
73 * [Result] represents a match of the search text on a library, type or member. | 73 * [Result] represents a match of the search text on a library, type or member. |
74 */ | 74 */ |
75 class Result { | 75 class Result { |
76 final StringMatch prefix; | 76 final StringMatch prefix; |
77 final StringMatch match; | 77 final StringMatch match; |
78 | 78 |
79 final String library; | 79 final String library; |
80 final String type; | 80 final String type; |
81 final String args; | 81 final String args; |
82 final String kind; | 82 final String kind; |
83 final String url; | 83 final String url; |
84 | 84 |
85 TableRowElement row; | 85 TableRowElement row; |
86 | 86 |
87 Result(this.match, this.kind, this.url, | 87 Result(this.match, this.kind, this.url, |
88 [this.library, this.type, String args, this.prefix]) | 88 [this.library, this.type, String args, this.prefix]) |
89 : this.args = args != null ? '<$args>' : ''; | 89 : this.args = args != null ? '<$args>' : ''; |
90 | 90 |
91 bool get isTopLevel() => prefix == null && type == null; | 91 bool get isTopLevel => prefix == null && type == null; |
92 | 92 |
93 void addRow(TableElement table) { | 93 void addRow(TableElement table) { |
94 if (row != null) return; | 94 if (row != null) return; |
95 | 95 |
96 clickHandler(Event event) { | 96 clickHandler(Event event) { |
97 window.location.href = url; | 97 window.location.href = url; |
98 hideDropDown(); | 98 hideDropDown(); |
99 } | 99 } |
100 | 100 |
101 row = table.insertRow(table.rows.length); | 101 row = table.insertRow(table.rows.length); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Sort type alphabetically. | 209 // Sort type alphabetically. |
210 // TODO(4805): Use [:type.compareToIgnoreCase] when supported. | 210 // TODO(4805): Use [:type.compareToIgnoreCase] when supported. |
211 result = a.type.toLowerCase().compareTo(b.type.toLowerCase()); | 211 result = a.type.toLowerCase().compareTo(b.type.toLowerCase()); |
212 if (result != 0) return result; | 212 if (result != 0) return result; |
213 } | 213 } |
214 | 214 |
215 // Sort match alphabetically. | 215 // Sort match alphabetically. |
216 // TODO(4805): Use [:text.compareToIgnoreCase] when supported. | 216 // TODO(4805): Use [:text.compareToIgnoreCase] when supported. |
217 return a.match.text.toLowerCase().compareTo(b.match.text.toLowerCase()); | 217 return a.match.text.toLowerCase().compareTo(b.match.text.toLowerCase()); |
218 } | 218 } |
OLD | NEW |