-
Notifications
You must be signed in to change notification settings - Fork 346
Adds a basic dialog for opening a file #3342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8c28003
Switch to cmd + p
elliette 5713b27
cmd + p / esc toggles visivility (prints whether the modal should be …
elliette 89f1147
Switch branches
elliette 4ad4682
Autocomplete with hardcoded data
elliette 41b1a7f
Use actual scripts instead of hardcoded data
elliette fec4710
Merge branch 'master' into file-opener
elliette 9422938
show open list of files before user starts searching
elliette 7affc1f
Close the dialog when a file is selected
elliette 75ae554
Close dialog on ESC
elliette e41166c
Make the dialog look a little nicer
elliette 7df45bb
Add icon and hotkeys to menu
elliette c80f9e6
Remove old code
elliette 5434042
Hide the dialog
elliette b4b309f
Responding to comments
elliette 3662ea7
add comment
elliette 6481a47
Merge branch 'master' into file-opener
elliette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Copyright 2021 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. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
import 'package:vm_service/vm_service.dart'; | ||
|
||
import '../auto_dispose_mixin.dart'; | ||
import '../common_widgets.dart'; | ||
import '../dialogs.dart'; | ||
import '../theme.dart'; | ||
import '../ui/search.dart'; | ||
import '../utils.dart'; | ||
import 'debugger_controller.dart'; | ||
|
@@ -16,11 +20,9 @@ const int numOfMatchesToShow = 6; | |
class FileSearchField extends StatefulWidget { | ||
const FileSearchField({ | ||
@required this.controller, | ||
@required this.handleClose, | ||
}); | ||
|
||
final DebuggerController controller; | ||
final Function handleClose; | ||
|
||
@override | ||
_FileSearchFieldState createState() => _FileSearchFieldState(); | ||
|
@@ -29,32 +31,35 @@ class FileSearchField extends StatefulWidget { | |
class _FileSearchFieldState extends State<FileSearchField> | ||
with SearchFieldMixin, AutoDisposeMixin { | ||
AutoCompleteController _autoCompleteController; | ||
final Map<String, ScriptRef> _scriptsCache = {}; | ||
|
||
final _scriptsCache = <String, ScriptRef>{}; | ||
|
||
final fileSearchFieldKey = GlobalKey(debugLabel: 'fileSearchFieldKey'); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_autoCompleteController = AutoCompleteController(); | ||
_autoCompleteController.currentDefaultIndex = 0; | ||
_autoCompleteController = AutoCompleteController()..currentDefaultIndex = 0; | ||
|
||
addAutoDisposeListener( | ||
_autoCompleteController.selectTheSearchNotifier, _handleSearch); | ||
addAutoDisposeListener( | ||
_autoCompleteController.searchNotifier, _handleSearch); | ||
addAutoDisposeListener(_autoCompleteController.searchAutoCompleteNotifier, | ||
_handleAutoCompleteOverlay); | ||
|
||
_autoCompleteController.selectTheSearch = true; | ||
SchedulerBinding.instance.addPostFrameCallback((_) => _handleSearch()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment explaining why this needs to be in a post frame callback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks! |
||
} | ||
|
||
void _handleSearch() { | ||
final query = _autoCompleteController.search; | ||
final matches = findMatches(query, widget.controller.sortedScripts.value); | ||
matches.forEach(_addScriptRefToCache); | ||
_autoCompleteController.searchAutoComplete.value = | ||
matches.map((scriptRef) => scriptRef.uri).toList(); | ||
_handleAutoCompleteOverlay(); | ||
if (matches.isEmpty) { | ||
_autoCompleteController.searchAutoComplete.value = ['No files found.']; | ||
} else { | ||
matches.forEach(_addScriptRefToCache); | ||
_autoCompleteController.searchAutoComplete.value = | ||
matches.map((scriptRef) => scriptRef.uri).toList(); | ||
} | ||
} | ||
|
||
void _handleAutoCompleteOverlay() { | ||
|
@@ -66,9 +71,7 @@ class _FileSearchFieldState extends State<FileSearchField> | |
} | ||
|
||
void _addScriptRefToCache(ScriptRef scriptRef) { | ||
if (!_scriptsCache.containsKey(scriptRef.uri)) { | ||
_scriptsCache[scriptRef.uri] = scriptRef; | ||
} | ||
_scriptsCache.putIfAbsent(scriptRef.uri, () => scriptRef); | ||
} | ||
|
||
@override | ||
|
@@ -78,24 +81,17 @@ class _FileSearchFieldState extends State<FileSearchField> | |
return Container( | ||
decoration: BoxDecoration( | ||
border: Border( | ||
elliette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
top: BorderSide(color: theme.focusColor), | ||
top: defaultBorderSide(theme), | ||
), | ||
), | ||
padding: const EdgeInsets.all(8.0), | ||
child: Row( | ||
children: [ | ||
const SizedBox(width: 8.0), | ||
Expanded( | ||
child: buildAutoCompleteSearchField( | ||
controller: _autoCompleteController, | ||
searchFieldKey: fileSearchFieldKey, | ||
searchFieldEnabled: true, | ||
shouldRequestFocus: true, | ||
closeOverlayOnEscape: false, | ||
onSelection: _onSelection, | ||
), | ||
), | ||
], | ||
padding: const EdgeInsets.all(denseSpacing), | ||
child: buildAutoCompleteSearchField( | ||
controller: _autoCompleteController, | ||
searchFieldKey: fileSearchFieldKey, | ||
searchFieldEnabled: true, | ||
shouldRequestFocus: true, | ||
closeOverlayOnEscape: false, | ||
onSelection: _onSelection, | ||
), | ||
); | ||
} | ||
|
@@ -104,7 +100,7 @@ class _FileSearchFieldState extends State<FileSearchField> | |
final scriptRef = _scriptsCache[scriptUri]; | ||
widget.controller.showScriptLocation(ScriptLocation(scriptRef)); | ||
_scriptsCache.clear(); | ||
widget.handleClose(); | ||
Navigator.of(context).pop(dialogDefaultContext); | ||
} | ||
|
||
@override | ||
|
@@ -134,7 +130,7 @@ List<ScriptRef> findMatches( | |
.where((scriptRef) => scriptRef.uri.caseInsensitiveFuzzyMatch(query)) | ||
.toList(); | ||
|
||
return takeTopMatches([...exactMatches, ...fuzzyMatches, ...scriptRefs]); | ||
return takeTopMatches([...exactMatches, ...fuzzyMatches]); | ||
} | ||
|
||
List<ScriptRef> takeTopMatches(List<ScriptRef> allMatches) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.