Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 220cb0e

Browse files
author
Ryan Browne
committed
Use an improved regex that does not have have to iterate through the entire string, and can just backtrack at most the last 2 characters.
Signed-off-by: Ryan Browne <[email protected]>
1 parent 10d2e3f commit 220cb0e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/autocomplete/EmojiProvider.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ function score(query, space) {
6464
}
6565

6666
function colonsTrimmed(str: string): string {
67-
// Trim off leading and potentially trailing `:` to correctly match the emoji data as they exist in emojibase.
68-
// Notes: The regex is pinned to the start and end of the string so that we can use the lazy-capturing `*?` matcher.
69-
// It needs to be lazy so that the trailing `:` is not captured in the replacement group, if it exists.
70-
return str.replace(/^:(.*?):?$/, "$1");
67+
// Trim off leading and potentially trailing `:` to correctly match the emoji shortcode names as they exist in emojibase.
68+
return str.replace(/^:(.*[^:]):?$/, "$1");
7169
}
7270

7371
export default class EmojiProvider extends AutocompleteProvider {

0 commit comments

Comments
 (0)