Skip to content

Commit

Permalink
chore: do not use fuzzy match for emojiComplete (misskey-dev#13384)
Browse files Browse the repository at this point in the history
cheery-picked from anatawa12/misskey@47c4a6e

* fix code quality issues

Co-authored-by: anatawa12 <anatawa12@icloud.com>
  • Loading branch information
u1-liquid and anatawa12 committed Mar 30, 2024
1 parent 70538fd commit 11f3d5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 1 addition & 7 deletions packages/frontend/src/components/MkAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion packages/frontend/src/scripts/search-emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand All @@ -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 => {
Expand Down

0 comments on commit 11f3d5d

Please sign in to comment.