From 30688016a012415e67b125af7103265129425c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Tue, 27 Feb 2024 10:59:09 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend/search-emoji):=20Unicode=E3=81=AE?= =?UTF-8?q?=E7=B5=B5=E6=96=87=E5=AD=97=E3=81=A8=E5=90=8C=E3=81=98=E5=90=8D?= =?UTF-8?q?=E5=89=8D=E3=81=AE=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E7=B5=B5?= =?UTF-8?q?=E6=96=87=E5=AD=97=E3=81=8CMkAutocomplete=E3=81=AA=E3=81=A9?= =?UTF-8?q?=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3=20(MisskeyIO#485)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/scripts/search-emoji.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/frontend/src/scripts/search-emoji.ts b/packages/frontend/src/scripts/search-emoji.ts index 07f55e5531..b74a4fd3d6 100644 --- a/packages/frontend/src/scripts/search-emoji.ts +++ b/packages/frontend/src/scripts/search-emoji.ts @@ -20,7 +20,7 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) // 完全一致(エイリアスなし) emojiDb.some(x => { 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; }); @@ -28,8 +28,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) // 完全一致(エイリアス込み) if (matched.size < max) { emojiDb.some(x => { - if (x.name === query && !matched.has(x.aliasOf ?? x.name)) { - matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length + 2 }); + if (x.name === query && !matched.has(x.emoji)) { + matched.set(x.emoji, { emoji: x, score: query.length + 2 }); } return matched.size === max; }); @@ -38,8 +38,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) // 前方一致(エイリアスなし) if (matched.size < max) { emojiDb.some(x => { - if (x.name.startsWith(query) && !x.aliasOf && !matched.has(x.name)) { - matched.set(x.name, { emoji: x, score: query.length + 1 }); + if (x.name.startsWith(query) && !x.aliasOf && !matched.has(x.emoji)) { + matched.set(x.emoji, { emoji: x, score: query.length + 1 }); } return matched.size === max; }); @@ -48,8 +48,8 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) // 前方一致(エイリアス込み) if (matched.size < max) { emojiDb.some(x => { - if (x.name.startsWith(query) && !matched.has(x.aliasOf ?? x.name)) { - matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length }); + if (x.name.startsWith(query) && !matched.has(x.emoji)) { + matched.set(x.emoji, { emoji: x, score: query.length }); } return matched.size === max; }); @@ -58,14 +58,14 @@ export function searchEmoji(query: string | null, emojiDb: EmojiDef[], max = 30) // 部分一致(エイリアス込み) if (matched.size < max) { emojiDb.some(x => { - if (x.name.includes(query) && !matched.has(x.aliasOf ?? x.name)) { - matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length - 1 }); + if (x.name.includes(query) && !matched.has(x.emoji)) { + matched.set(x.emoji, { emoji: x, score: query.length - 1 }); } return matched.size === max; }); } - // 簡易あいまい検索(3文字以上) + // 簡易あいまい検索(4文字以上) if (matched.size < max && query.length > 3) { const queryChars = [...query]; const hitEmojis = new Map(); @@ -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)) { - hitEmojis.set(x.aliasOf ?? x.name, { emoji: x, score: hit - 2 }); + if (hit > Math.ceil(queryChars.length / 2) && hit - 2 > (matched.get(x.emoji)?.score ?? 0)) { + 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()] .sort((x, y) => y.score - x.score) .slice(0, 6) - .forEach(it => matched.set(it.emoji.name, it)); + .forEach(it => matched.set(it.emoji.emoji, it)); } return [...matched.values()]