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 => {