chore: do not use fuzzy match for emojiComplete (misskey-dev#13384) (MisskeyIO#586)

cheery-picked from anatawa12/misskey@47c4a6ed79

* fix code quality issues

Co-authored-by: anatawa12 <anatawa12@icloud.com>
This commit is contained in:
まっちゃとーにゅ 2024-04-01 03:12:02 +09:00 committed by GitHub
parent 70538fd696
commit 9f6b433df2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View file

@ -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;

View file

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