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

Commit

Permalink
Use an improved regex that does not have have to iterate through the …
Browse files Browse the repository at this point in the history
…entire string, and can just backtrack at most the last 2 characters.

Signed-off-by: Ryan Browne <code@commonlawfeature.com>
  • Loading branch information
Ryan Browne committed Apr 9, 2022
1 parent 10d2e3f commit 220cb0e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/autocomplete/EmojiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ function score(query, space) {
}

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

export default class EmojiProvider extends AutocompleteProvider {
Expand Down

0 comments on commit 220cb0e

Please sign in to comment.