Skip to content

Commit 6b3d426

Browse files
committed
autocomplete [nfc]: Generalize find-intent loop slightly
This makes room for this loop to look for other autocomplete markers besides `@`.
1 parent ce5beaa commit 6b3d426

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/model/autocomplete.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ extension ComposeContentAutocomplete on ComposeContentController {
3333

3434
final textUntilCursor = text.substring(0, selection.end);
3535
for (int pos = selection.end - 1; pos >= earliest; pos--) {
36-
if (textUntilCursor[pos] != '@') {
37-
continue;
36+
final charAtPos = textUntilCursor[pos];
37+
if (charAtPos == '@') {
38+
final match = _mentionIntentRegex.matchAsPrefix(textUntilCursor, pos);
39+
if (match == null) {
40+
continue;
41+
}
42+
if (selection.start < pos) {
43+
// See comment about [TextSelection.isCollapsed] above.
44+
return null;
45+
}
46+
return AutocompleteIntent(
47+
syntaxStart: pos,
48+
query: MentionAutocompleteQuery(match[2]!, silent: match[1]! == '_'),
49+
textEditingValue: value);
3850
}
39-
final match = _mentionIntentRegex.matchAsPrefix(textUntilCursor, pos);
40-
if (match == null) {
41-
continue;
42-
}
43-
if (selection.start < pos) {
44-
// See comment about [TextSelection.isCollapsed] above.
45-
return null;
46-
}
47-
return AutocompleteIntent(
48-
syntaxStart: pos,
49-
query: MentionAutocompleteQuery(match[2]!, silent: match[1]! == '_'),
50-
textEditingValue: value);
5151
}
5252
return null;
5353
}

0 commit comments

Comments
 (0)