Skip to content

Commit 0b28227

Browse files
committed
autocomplete [nfc]: Simplify intent-finding loop slightly
1 parent 726ec5a commit 0b28227

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/model/autocomplete.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:flutter/foundation.dart';
24
import 'package:flutter/services.dart';
35

@@ -18,12 +20,13 @@ extension ComposeContentAutocomplete on ComposeContentController {
1820
// see below.
1921
return null;
2022
}
23+
24+
// To avoid spending a lot of time searching for autocomplete intents
25+
// in long messages, we bound how far back we look for the intent's start.
26+
final earliest = max(0, selection.end - 30);
27+
2128
final textUntilCursor = text.substring(0, selection.end);
22-
for (
23-
int position = selection.end - 1;
24-
position >= 0 && (selection.end - position <= 30);
25-
position--
26-
) {
29+
for (int position = selection.end - 1; position >= earliest; position--) {
2730
if (textUntilCursor[position] != '@') {
2831
continue;
2932
}

0 commit comments

Comments
 (0)