From 9f6b433df2cbc2c58566725430d1a58f721bc573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Mon, 1 Apr 2024 03:12:02 +0900 Subject: [PATCH] chore: do not use fuzzy match for emojiComplete (misskey-dev#13384) (MisskeyIO#586) cheery-picked from anatawa12/misskey@47c4a6ed79451c9a9b60bf324568090d11dd0968 * fix code quality issues Co-authored-by: anatawa12 --- packages/frontend/src/components/MkAutocomplete.vue | 8 +------- packages/frontend/src/scripts/search-emoji.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/components/MkAutocomplete.vue b/packages/frontend/src/components/MkAutocomplete.vue index 06de95ab19..43ce8bbb50 100644 --- a/packages/frontend/src/components/MkAutocomplete.vue +++ b/packages/frontend/src/components/MkAutocomplete.vue @@ -281,13 +281,7 @@ function exec() { emojis.value = searchEmoji(props.q, emojiDb.value); } else if (props.type === 'emojiComplete') { - if (!props.q || props.q === '') { - // 最近使った絵文字をサジェスト - emojis.value = defaultStore.state.recentlyUsedEmojis.map(emoji => unicodeEmojiDB.value.find(dbEmoji => dbEmoji.emoji === emoji)).filter(x => x) as EmojiDef[]; - return; - } - - emojis.value = searchEmoji(props.q, unicodeEmojiDB.value); + emojis.value = searchEmoji(props.q, unicodeEmojiDB.value, true); } else if (props.type === 'mfmTag') { if (!props.q || props.q === '') { mfmTags.value = MFM_TAGS; diff --git a/packages/frontend/src/scripts/search-emoji.ts b/packages/frontend/src/scripts/search-emoji.ts index 2e77e985b6..217d2672e7 100644 --- a/packages/frontend/src/scripts/search-emoji.ts +++ b/packages/frontend/src/scripts/search-emoji.ts @@ -16,7 +16,7 @@ export type EmojiDef = { }; type EmojiScore = { emoji: EmojiDef, score: number }; -export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30): EmojiDef[] { +export function searchEmoji(query: string | null, emojiDb: EmojiDef[], exact = false, max = 30): EmojiDef[] { if (!query) { return []; } @@ -40,6 +40,13 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) }); } + if (exact) { + return [...matched.values()] + .sort((x, y) => y.score - x.score) + .slice(0, max) + .map(it => it.emoji); + } + // 前方一致(エイリアスなし) if (matched.size < max) { emojiDb.some(x => {