Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suggestion): allow case-insensitive emoji suggestion #2565

Merged

Conversation

shuuji3
Copy link
Member

@shuuji3 shuuji3 commented Jan 21, 2024

fix #2552

Currently, we're simply comparing strings with startsWith() so users have to type the exact same case as its emoji id or shortcode.

This change supports a case-insensitive search despite either id/shortcode or user query containing any upper/lower cases.

Screenshot from 2024-01-21 17-19-08
Screenshot from 2024-01-21 17-14-32

Also, it looks like Mastodon's custom emoji search doesn't distinguish cases of shortcode: mastodon/mastodon#15738

Copy link

stackblitz bot commented Jan 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Jan 21, 2024

Deploy Preview for elk-docs canceled.

Name Link
🔨 Latest commit 24df5ed
🔍 Latest deploy log https://app.netlify.com/sites/elk-docs/deploys/65acff28920d200008859a8d

Copy link

netlify bot commented Jan 21, 2024

Deploy Preview for elk-zone ready!

Name Link
🔨 Latest commit 24df5ed
🔍 Latest deploy log https://app.netlify.com/sites/elk-zone/deploys/65acff280dfcc5000875b1d4
😎 Deploy Preview https://deploy-preview-2565--elk-zone.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 67 to 70
.then(data => Object.values(data.emojis).filter(({ id }) => id.toLowerCase().startsWith(query.toLowerCase())))

const customEmojis: CustomEmoji[] = currentCustomEmojis.value.emojis
.filter(emoji => emoji.shortcode.startsWith(query))
.filter(emoji => emoji.shortcode.toLowerCase().startsWith(query.toLowerCase()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should cache query.toLowerCase() to avoid recomputing it during the loops.
But I think we should do the same with shortcode and id, and cache the result of import('@emoji-mart/data') with the data as we needed in lowercase. This will also speed up things

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I removed multiple calls of toLowerCase() for query.

Also, I used useAsyncData to cache emojimart data import. Is this the right approach for caching?

Regarding making id and shortcode lowercase, there is an issue. If we lower the shortcode beforehand, we cannot show the original shortcode for users like the below.

Screenshot from 2024-01-21 18-29-35

This is problematic since some custom emoji use camelcase naming like :thisIsCamelCaseEmojiName:. The lowercased name :thisiscamelcaseemojiname: is a bit difficult to read.

Maybe we can keep as is since I assume it's not so heavy computation to call toLowerCase() as many times as emoji counts.

@shuuji3 shuuji3 force-pushed the fix/allow-case-insensitive-emoji-search branch from c8a6c46 to c6c8004 Compare January 21, 2024 10:53
@shuuji3 shuuji3 force-pushed the fix/allow-case-insensitive-emoji-search branch from c6c8004 to 24df5ed Compare January 21, 2024 11:25
@patak-dev patak-dev added this pull request to the merge queue Feb 19, 2024
Merged via the queue into elk-zone:main with commit bf0c562 Feb 19, 2024
13 checks passed
@shuuji3 shuuji3 deleted the fix/allow-case-insensitive-emoji-search branch February 19, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emoji Picker is case sensitive
2 participants