registerTextChanged method
List<String> ?
registerTextChanged({
- required String content,
- required TextSelection selection,
- required KeyEvent keyEvent,
If a valid word (present in the dictionary) is being typed, a List<String> with the valid completions is returned, and null otherwise. This method should only be called if a LSPClient is not in use.
Implementation
List<String>? registerTextChanged({
required String content,
required TextSelection selection,
required KeyEvent keyEvent,
}) {
if (selection.isCollapsed) {
if (keyEvent.logicalKey == LogicalKeyboardKey.backspace) {
final res = _updateCompletions(
content: content,
selection: TextSelection.collapsed(offset: selection.baseOffset - 2),
);
return res;
} else {
final String char = HardwareKeyboard.instance.isShiftPressed
? keyEvent.logicalKey.keyLabel
: keyEvent.logicalKey.keyLabel.toLowerCase();
content = "$content$char";
if (utils.charIsAlphaNum(char) || (const [' ', '\n']).contains(char)) {
if (utils.charIsAlphaNum(content[selection.baseOffset])) {
return _updateCompletions(
content: content,
selection: selection,
);
} else {
final word = _parseWordBeforeToken(
content: content, pos: selection.baseOffset - 1);
// update the dictionary
if (!dictionary.contains(word)) dictionary.add(word);
dictionary.sort();
}
}
}
}
showingCompletions = false;
return currentCompletions = null;
}