fix(frontend/search-emoji): Unicodeの絵文字と同じ名前のカスタム絵文字がMkAutocompleteなどで表示されない問題を修正 (MisskeyIO#485)
This commit is contained in:
parent
c8b1ef0971
commit
30688016a0
|
@ -20,7 +20,7 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
// 完全一致(エイリアスなし)
|
// 完全一致(エイリアスなし)
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name === query && !x.aliasOf) {
|
if (x.name === query && !x.aliasOf) {
|
||||||
matched.set(x.name, { emoji: x, score: query.length + 3 });
|
matched.set(x.emoji, { emoji: x, score: query.length + 3 });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
return matched.size === max;
|
||||||
});
|
});
|
||||||
|
@ -28,8 +28,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
// 完全一致(エイリアス込み)
|
// 完全一致(エイリアス込み)
|
||||||
if (matched.size < max) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name === query && !matched.has(x.aliasOf ?? x.name)) {
|
if (x.name === query && !matched.has(x.emoji)) {
|
||||||
matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length + 2 });
|
matched.set(x.emoji, { emoji: x, score: query.length + 2 });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
return matched.size === max;
|
||||||
});
|
});
|
||||||
|
@ -38,8 +38,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
// 前方一致(エイリアスなし)
|
// 前方一致(エイリアスなし)
|
||||||
if (matched.size < max) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name.startsWith(query) && !x.aliasOf && !matched.has(x.name)) {
|
if (x.name.startsWith(query) && !x.aliasOf && !matched.has(x.emoji)) {
|
||||||
matched.set(x.name, { emoji: x, score: query.length + 1 });
|
matched.set(x.emoji, { emoji: x, score: query.length + 1 });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
return matched.size === max;
|
||||||
});
|
});
|
||||||
|
@ -48,8 +48,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
// 前方一致(エイリアス込み)
|
// 前方一致(エイリアス込み)
|
||||||
if (matched.size < max) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name.startsWith(query) && !matched.has(x.aliasOf ?? x.name)) {
|
if (x.name.startsWith(query) && !matched.has(x.emoji)) {
|
||||||
matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length });
|
matched.set(x.emoji, { emoji: x, score: query.length });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
return matched.size === max;
|
||||||
});
|
});
|
||||||
|
@ -58,14 +58,14 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
// 部分一致(エイリアス込み)
|
// 部分一致(エイリアス込み)
|
||||||
if (matched.size < max) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name.includes(query) && !matched.has(x.aliasOf ?? x.name)) {
|
if (x.name.includes(query) && !matched.has(x.emoji)) {
|
||||||
matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length - 1 });
|
matched.set(x.emoji, { emoji: x, score: query.length - 1 });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
return matched.size === max;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 簡易あいまい検索(3文字以上)
|
// 簡易あいまい検索(4文字以上)
|
||||||
if (matched.size < max && query.length > 3) {
|
if (matched.size < max && query.length > 3) {
|
||||||
const queryChars = [...query];
|
const queryChars = [...query];
|
||||||
const hitEmojis = new Map<string, EmojiScore>();
|
const hitEmojis = new Map<string, EmojiScore>();
|
||||||
|
@ -82,8 +82,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 半分以上の文字が含まれていればヒットとする
|
// 半分以上の文字が含まれていればヒットとする
|
||||||
if (hit > Math.ceil(queryChars.length / 2) && hit - 2 > (matched.get(x.aliasOf ?? x.name)?.score ?? 0)) {
|
if (hit > Math.ceil(queryChars.length / 2) && hit - 2 > (matched.get(x.emoji)?.score ?? 0)) {
|
||||||
hitEmojis.set(x.aliasOf ?? x.name, { emoji: x, score: hit - 2 });
|
hitEmojis.set(x.emoji, { emoji: x, score: hit - 2 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30)
|
||||||
[...hitEmojis.values()]
|
[...hitEmojis.values()]
|
||||||
.sort((x, y) => y.score - x.score)
|
.sort((x, y) => y.score - x.score)
|
||||||
.slice(0, 6)
|
.slice(0, 6)
|
||||||
.forEach(it => matched.set(it.emoji.name, it));
|
.forEach(it => matched.set(it.emoji.emoji, it));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...matched.values()]
|
return [...matched.values()]
|
||||||
|
|
Loading…
Reference in a new issue