@@ -114,18 +114,48 @@ final RegExp _emojiIntentRegex = (() {
114
114
// meaning "whitespace and punctuation, except not `:`":
115
115
// r'(?<=^|[[\s\p{Punctuation}]--[:]])'
116
116
117
- /// Characters that might be meant as part of (a query for) an emoji's name,
118
- /// other than whitespace.
117
+ // What possible emoji queries do we want to anticipate?
118
+ //
119
+ // First, look only for queries aimed at emoji names (and aliases);
120
+ // there's little point in searching by literal emoji here, because once the
121
+ // user has entered a literal emoji they can simply leave it in.
122
+ // (Searching by literal emoji is useful, by contrast, for adding a reaction.)
123
+ //
124
+ // Then, what are the possible names (including aliases)?
125
+ // For custom emoji, the names the server allows are r'^[0-9a-z_-]*[0-9a-z]$';
126
+ // see check_valid_emoji_name in zerver/lib/emoji.py.
127
+ // So only ASCII lowercase alnum, underscore, and dash.
128
+ // A few Unicode emoji have more general names in the server's list:
129
+ // Latin letters with diacritics, a few kana and kanji, and the name "+1".
130
+ // (And the only "Zulip extra emoji" has one name, "zulip".)
131
+ // Details: https://github.com/zulip/zulip-flutter/pull/1069#discussion_r1855964953
132
+ //
133
+ // We generalize [0-9a-z] to "any letter or number".
134
+ // That handles the existing names except "+1", plus a potential future
135
+ // loosening of the constraints on custom emoji's names.
136
+ //
137
+ // Then "+1" we take as a special case, without generalizing,
138
+ // in order to recognize that name without adding false positives.
139
+ //
140
+ // Even though there could be a custom emoji whose name begins with "-",
141
+ // we reject queries that begin that way: ":-" is much more likely to be
142
+ // the start of an emoticon.
143
+
144
+ /// Characters that might be meant as part of (a query for) an emoji's name
145
+ /// at any point in the query.
119
146
const nameCharacters = r'_\p{Letter}\p{Number}' ;
120
147
121
148
return RegExp (unicode: true ,
122
149
before
123
150
+ r':'
124
151
+ r'(|'
152
+ // Recognize '+' only as part of '+1', the only emoji name that has it.
153
+ + r'\+1?|'
125
154
// Reject on whitespace right after ':'; interpret that
126
155
// as the user choosing to get out of the emoji autocomplete.
127
- + r'[' + nameCharacters + r']'
128
- + r'[\s' + nameCharacters + r']*'
156
+ // Similarly reject starting with ':-', which is common for emoticons.
157
+ + r'[' + nameCharacters + r']'
158
+ + r'[-\s' + nameCharacters + r']*'
129
159
+ r')$' );
130
160
})();
131
161
0 commit comments