| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:html' hide Element; | 6 import 'dart:html' hide Element; |
| 7 import 'dart:html' as html show Element; | 7 import 'dart:html' as html show Element; |
| 8 import 'app.dart'; | 8 import 'app.dart'; |
| 9 import 'package:dartdoc_viewer/item.dart'; | 9 import 'package:dartdoc_viewer/item.dart'; |
| 10 import 'package:dartdoc_viewer/search.dart'; | 10 import 'package:dartdoc_viewer/search.dart'; |
| 11 import 'package:web_ui/web_ui.dart'; | 11 import 'package:web_ui/web_ui.dart'; |
| 12 import 'package:web_ui/watcher.dart' as watchers; | 12 import 'package:web_ui/watcher.dart' as watchers; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Component implementing the Dartdoc_viewer search. | 15 * Component implementing the Dartdoc_viewer search. |
| 16 */ | 16 */ |
| 17 class Search extends WebComponent { | 17 class Search extends WebComponent { |
| 18 /** Search query. */ | 18 |
| 19 @observable String searchQuery = ""; | |
| 20 List<SearchResult> results = toObservable(<SearchResult>[]); | 19 List<SearchResult> results = toObservable(<SearchResult>[]); |
| 21 String _lastQuery; | 20 String _lastQuery; |
| 22 @observable bool isFocused = false; | 21 @observable bool isFocused = false; |
| 23 | 22 |
| 24 int currentIndex = -1; | 23 int currentIndex = -1; |
| 25 | 24 |
| 26 void updateResults() { | 25 void updateResults() { |
| 27 currentIndex = -1; | 26 currentIndex = -1; |
| 28 results.clear(); | 27 results.clear(); |
| 29 results.addAll(lookupSearchResults(searchQuery, viewer.isDesktop ? 10 : 5)); | 28 results.addAll(lookupSearchResults(searchQuery, viewer.isDesktop ? 10 : 5)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Allow writing 's' in the search input. | 108 // Allow writing 's' in the search input. |
| 110 document.query('#q').focus(); | 109 document.query('#q').focus(); |
| 111 event.preventDefault(); | 110 event.preventDefault(); |
| 112 } else if (event.keyCode == KeyCode.ESC) { | 111 } else if (event.keyCode == KeyCode.ESC) { |
| 113 document.body.focus(); | 112 document.body.focus(); |
| 114 isFocused = false; | 113 isFocused = false; |
| 115 event.preventDefault(); | 114 event.preventDefault(); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 } | 117 } |
| OLD | NEW |