Skip to content

Commit

Permalink
絵文字ピッカーで平仮名のエイリアスにローマ字でマッチできるように (#77)
Browse files Browse the repository at this point in the history
Co-authored-by: Adzuki <[email protected]>
  • Loading branch information
adzukimame and adzukimame authored Jul 4, 2024
1 parent af7f129 commit 24fc8bd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 46 deletions.
1 change: 1 addition & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@discordapp/twemoji": "15.0.3",
"@github/webauthn-json": "2.1.1",
"@koozaki/romaji-conv": "2.0.29",
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
"@misskey-dev/browser-image-resizer": "2024.1.0",
"@rollup/plugin-json": "6.1.0",
Expand Down
32 changes: 32 additions & 0 deletions packages/frontend/src/components/MkEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { ref, shallowRef, computed, watch, onMounted } from 'vue';
import * as Misskey from 'misskey-js';
import * as romajiConv from '@koozaki/romaji-conv';
import XSection from '@/components/MkEmojiPicker.section.vue';
import {
emojilist,
Expand Down Expand Up @@ -278,6 +279,37 @@ watch(q, () => {
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;

// 日本語のための対応

// 約物
// 「?」「!」「…」以外は無視
const newQ1 = newQ
.replace(/__q/g, '?') // 「__q」を「?」に
.replace(/__i/g, '!') // 「__i」を「!」に
.replace(/__ooo/g, '…') // 「__ooo」を「…」に
.replace(/_/g, ''); // 「_」を取り除く
const newQ1j = romajiConv.toHiragana(newQ1);

// 「ん」の表記を「nn」に合わせる
// んな、んに、んぬ、んね、んの、んや、んゆ、んよ
//「minna(みんな)」→「minnna」、「panya(パン屋)」→「pannya」等
const newQ2 = newQ1.replace(/(?<!n)nn(a|i|u|e|o)/g, 'nnn$1').replace(/(?<!n)ny(a|u|o)/g, 'nny$1');
const newQ2j = romajiConv.toHiragana(newQ2);

// 「ん」の表記を「nn」に合わせる
// んにゃ、んにゅ、んにょ
// 「hannya(般若)」→「hannnya」等
const newQ3 = newQ2.replace(/(?<!n)nny(a|u|o)/g, 'nnny$1');
const newQ3j = romajiConv.toHiragana(newQ3);

for (const emoji of emojis) {
if (emoji.aliases.some(alias => alias.includes(newQ1j) || alias.includes(newQ2j) || alias.includes(newQ3j))) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
}

return matches;
Expand Down
Loading

0 comments on commit 24fc8bd

Please sign in to comment.