Skip to content

Commit 1c01908

Browse files
committed
autocomplete [nfc]: Short-circuit intent-finding on long selection
This is NFC because when this condition is true, the only return statements below that can actually be reached are the ones that return null. In the code as it is, this makes a small optimization. But it also will help simplify an upcoming refactor.
1 parent 0b28227 commit 1c01908

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/model/autocomplete.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ extension ComposeContentAutocomplete on ComposeContentController {
2525
// in long messages, we bound how far back we look for the intent's start.
2626
final earliest = max(0, selection.end - 30);
2727

28+
if (selection.start < earliest) {
29+
// The selection extends to before any position we'd consider
30+
// for the start of the intent. So there can't be a match.
31+
return null;
32+
}
33+
2834
final textUntilCursor = text.substring(0, selection.end);
2935
for (int position = selection.end - 1; position >= earliest; position--) {
3036
if (textUntilCursor[position] != '@') {

0 commit comments

Comments
 (0)