Skip to content
Snippets Groups Projects
Unverified Commit 2a41f6c3 authored by YS's avatar YS Committed by GitHub
Browse files

enhance: Unicode絵文字名逆引き効率化 (#9757)


* Unicode絵文字名前取得を連想配列で行う

* Unicode絵文字事前カテゴリ集計

* Mapを使用

* Update packages/frontend/src/scripts/emojilist.ts

Co-authored-by: default avatarAcid Chicken (硫酸鶏) <root@acid-chicken.com>

---------

Co-authored-by: default avatartamaina <tamaina@hotmail.co.jp>
Co-authored-by: default avatarAcid Chicken (硫酸鶏) <root@acid-chicken.com>
parent 671d21a2
No related branches found
No related tags found
No related merge requests found
......@@ -74,7 +74,7 @@
</div>
<div v-once class="group">
<header class="_acrylic">{{ i18n.ts.emoji }}</header>
<XSection v-for="category in categories" :key="category" :emojis="emojilist.filter(e => e.category === category).map(e => e.char)" @chosen="chosen">{{ category }}</XSection>
<XSection v-for="category in categories" :key="category" :emojis="emojiCharByCategory.get(category) ?? []" @chosen="chosen">{{ category }}</XSection>
</div>
</div>
<div class="tabs">
......@@ -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';
......
......@@ -12,6 +12,25 @@ import _emojilist from '../emojilist.json';
export const emojilist = _emojilist as UnicodeEmojiDef[];
const _indexByChar = new Map<string, number>();
const _charGroupByCategory = new Map<string, string[]>();
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment