From 2a41f6c383cc9963aa4a56efafd8dd50abd38709 Mon Sep 17 00:00:00 2001 From: YS <47836716+yszkst@users.noreply.github.com> Date: Wed, 1 Feb 2023 11:25:13 +0900 Subject: [PATCH] =?UTF-8?q?enhance:=20Unicode=E7=B5=B5=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=90=8D=E9=80=86=E5=BC=95=E3=81=8D=E5=8A=B9=E7=8E=87=E5=8C=96?= =?UTF-8?q?=20(#9757)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Unicode絵文字名前取得を連想配列で行う * Unicode絵文字事前カテゴリ集計 * Mapを使用 * Update packages/frontend/src/scripts/emojilist.ts Co-authored-by: Acid Chicken (硫酸鶏) --------- Co-authored-by: tamaina Co-authored-by: Acid Chicken (硫酸鶏) --- .../frontend/src/components/MkEmojiPicker.vue | 4 ++-- packages/frontend/src/scripts/emojilist.ts | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/components/MkEmojiPicker.vue b/packages/frontend/src/components/MkEmojiPicker.vue index 39e274ba11..2063ab4dec 100644 --- a/packages/frontend/src/components/MkEmojiPicker.vue +++ b/packages/frontend/src/components/MkEmojiPicker.vue @@ -74,7 +74,7 @@
{{ i18n.ts.emoji }}
- {{ category }} + {{ category }}
@@ -90,7 +90,7 @@ import { ref, shallowRef, computed, watch, onMounted } from 'vue'; import * as Misskey from 'misskey-js'; import XSection from '@/components/MkEmojiPicker.section.vue'; -import { emojilist, UnicodeEmojiDef, unicodeEmojiCategories as categories } from '@/scripts/emojilist'; +import { emojilist, emojiCharByCategory, UnicodeEmojiDef, unicodeEmojiCategories as categories } from '@/scripts/emojilist'; import MkRippleEffect from '@/components/MkRippleEffect.vue'; import * as os from '@/os'; import { isTouchUsing } from '@/scripts/touch'; diff --git a/packages/frontend/src/scripts/emojilist.ts b/packages/frontend/src/scripts/emojilist.ts index bc52fa7a43..2e853b58b5 100644 --- a/packages/frontend/src/scripts/emojilist.ts +++ b/packages/frontend/src/scripts/emojilist.ts @@ -12,6 +12,25 @@ import _emojilist from '../emojilist.json'; export const emojilist = _emojilist as UnicodeEmojiDef[]; +const _indexByChar = new Map(); +const _charGroupByCategory = new Map(); +emojilist.forEach((emo, i) => { + _indexByChar.set(emo.char, i); + + if (_charGroupByCategory.has(emo.category)) { + _charGroupByCategory.get(emo.category)?.push(emo.char); + } else { + _charGroupByCategory.set(emo.category, [emo.char]); + } +}); + +export const emojiCharByCategory = _charGroupByCategory; + export function getEmojiName(char: string): string | undefined { - return emojilist.find(emo => emo.char === char)?.name; + const idx = _indexByChar.get(char); + if (typeof idx === 'undefined') { + return undefined; + } else { + return emojilist[idx].name; + } }