diff --git a/lib/services/text_autocompletion.dart b/lib/services/text_autocompletion.dart index 48a7b130..3d26a316 100644 --- a/lib/services/text_autocompletion.dart +++ b/lib/services/text_autocompletion.dart @@ -78,14 +78,13 @@ class TextAutocompletionService { onPrefixMissing(); } - var newText = text.substring(0, cursorPosition - lastWord.length) + - '$prefix$value ' + - text.substring(cursorPosition); - var newSelection = TextSelection.collapsed( - offset: cursorPosition - lastWord.length + prefix.length + value.length + 1); - - textController.value = - TextEditingValue(text: newText, selection: newSelection); + var newTextStart = + text.substring(0, cursorPosition - lastWord.length) + '$prefix$value '; + var newTextEnd = text.substring(cursorPosition); + var newSelection = TextSelection.collapsed(offset: newTextStart.length); + + textController.value = TextEditingValue( + text: newTextStart + newTextEnd, selection: newSelection); } }