Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
♻️ Remove magic number from cursor offset in auto completer
Browse files Browse the repository at this point in the history
  • Loading branch information
Komposten committed Jun 19, 2020
1 parent f21fe05 commit e66eeb6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/services/text_autocompletion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit e66eeb6

Please sign in to comment.