Skip to content

Commit 5ed64db

Browse files
authored
Allow to disable autocompletion, close suggestions with Escape key (akvelon#206) (akvelon#219) (akvelon#226)
1 parent db569a0 commit 5ed64db

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ The editor performs no syntax analysis and so cannot tell if a given class reall
363363
the method the user is typing. This feature is meant to simplify typing but not to be relied on
364364
when exploring classes and methods.
365365

366-
Autocompletion currently cannot be disabled.
366+
To disable autocompletion:
367+
368+
```dart
369+
controller.popupController.enabled = false;
370+
```
367371

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

lib/src/code_field/code_controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ class CodeController extends TextEditingController {
281281
insertSelectedWord();
282282
return KeyEventResult.handled;
283283
}
284+
if (event.logicalKey == LogicalKeyboardKey.escape) {
285+
popupController.hide();
286+
return KeyEventResult.handled;
287+
}
284288
}
285289

286290
return KeyEventResult.ignored; // The framework will handle.

lib/src/wip/autocomplete/popup_controller.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class PopupController extends ChangeNotifier {
55
late List<String> suggestions;
66
int _selectedIndex = 0;
77
bool shouldShow = false;
8+
bool enabled = true;
89

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

2526
void show(List<String> suggestions) {
27+
if (enabled == false) {
28+
return;
29+
}
30+
2631
this.suggestions = suggestions;
2732
_selectedIndex = 0;
2833
shouldShow = true;

0 commit comments

Comments
 (0)