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:
parent
70538fd696
commit
9f6b433df2
|
@ -281,13 +281,7 @@ function exec() {
|
||||||
|
|
||||||
emojis.value = searchEmoji(props.q, emojiDb.value);
|
emojis.value = searchEmoji(props.q, emojiDb.value);
|
||||||
} else if (props.type === 'emojiComplete') {
|
} else if (props.type === 'emojiComplete') {
|
||||||
if (!props.q || props.q === '') {
|
emojis.value = searchEmoji(props.q, unicodeEmojiDB.value, true);
|
||||||
// 最近使った絵文字をサジェスト
|
|
||||||
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);
|
|
||||||
} else if (props.type === 'mfmTag') {
|
} else if (props.type === 'mfmTag') {
|
||||||
if (!props.q || props.q === '') {
|
if (!props.q || props.q === '') {
|
||||||
mfmTags.value = MFM_TAGS;
|
mfmTags.value = MFM_TAGS;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export type EmojiDef = {
|
||||||
};
|
};
|
||||||
type EmojiScore = { emoji: EmojiDef, score: number };
|
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) {
|
if (!query) {
|
||||||
return [];
|
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) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
|
|
Loading…
Reference in a new issue