Skip to content

Commit

Permalink
enhance(frontend): 絵文字ピッカー/オートコンプリートで完全一致の絵文字を優先するように (misskey-dev#12928
Browse files Browse the repository at this point in the history
) (#338)

Co-authored-by: 1step621 <onestep621@gmail.com>
  • Loading branch information
u1-liquid and 1STEP621 authored Jan 7, 2024
1 parent 91c2efa commit 23f1644
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/frontend/src/components/MkAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,24 @@ function emojiAutoComplete(query: string | null, emojiDb: EmojiDef[], max = 30):
}
const matched = new Map<string, EmojiScore>();
// 前方一致(エイリアスなし)
// 完全一致(エイリアス込み)
emojiDb.some(x => {
if (x.name.startsWith(query) && !x.aliasOf) {
matched.set(x.name, { emoji: x, score: query.length + 1 });
if (x.name === query && !matched.has(x.aliasOf ?? x.name)) {
matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length + 2 });
}
return matched.size === max;
});
// 前方一致(エイリアスなし)
if (matched.size < max) {
emojiDb.some(x => {
if (x.name.startsWith(query) && !x.aliasOf) {
matched.set(x.name, { emoji: x, score: query.length + 1 });
}
return matched.size === max;
});
}
// 前方一致(エイリアス込み)
if (matched.size < max) {
emojiDb.some(x => {
Expand Down
13 changes: 13 additions & 0 deletions packages/frontend/src/components/MkEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ watch(q, () => {
}
}
} else {
if (customEmojisMap.has(newQ)) {
matches.add(customEmojisMap.get(newQ)!);
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.aliases.some(alias => alias === newQ)) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.name.startsWith(newQ)) {
matches.add(emoji);
Expand Down

0 comments on commit 23f1644

Please sign in to comment.