Skip to content

Allow to disable autocompletion, close suggestions with Escape key (#206) (#219) #226

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 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ The editor performs no syntax analysis and so cannot tell if a given class reall
the method the user is typing. This feature is meant to simplify typing but not to be relied on
when exploring classes and methods.

Autocompletion currently cannot be disabled.
To disable autocompletion:

```dart
controller.popupController.enabled = false;
```

![Suggestions example](https://raw.githubusercontent.com/akvelon/flutter-code-editor/main/example/images/suggestions_example.gif)

Expand Down
4 changes: 4 additions & 0 deletions lib/src/code_field/code_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class CodeController extends TextEditingController {
insertSelectedWord();
return KeyEventResult.handled;
}
if (event.logicalKey == LogicalKeyboardKey.escape) {
popupController.hide();
return KeyEventResult.handled;
}
}

return KeyEventResult.ignored; // The framework will handle.
Expand Down
5 changes: 5 additions & 0 deletions lib/src/wip/autocomplete/popup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PopupController extends ChangeNotifier {
late List<String> suggestions;
int _selectedIndex = 0;
bool shouldShow = false;
bool enabled = true;

final ItemScrollController itemScrollController = ItemScrollController();
final ItemPositionsListener itemPositionsListener =
Expand All @@ -23,6 +24,10 @@ class PopupController extends ChangeNotifier {
int get selectedIndex => _selectedIndex;

void show(List<String> suggestions) {
if (enabled == false) {
return;
}

this.suggestions = suggestions;
_selectedIndex = 0;
shouldShow = true;
Expand Down