絵文字ピッカー/オートコンプリートで完全一致の絵文字を優先するように
This commit is contained in:
parent
7768385be2
commit
85d78256f7
|
@ -262,15 +262,24 @@ function emojiAutoComplete(query: string | null, emojiDb: EmojiDef[], max = 30):
|
||||||
}
|
}
|
||||||
|
|
||||||
const matched = new Map<string, EmojiScore>();
|
const matched = new Map<string, EmojiScore>();
|
||||||
|
// 完全一致(エイリアス込み)
|
||||||
// 前方一致(エイリアスなし)
|
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
if (x.name.startsWith(query) && !x.aliasOf) {
|
if (x.name === query && !matched.has(x.aliasOf ?? x.name)) {
|
||||||
matched.set(x.name, { emoji: x, score: query.length + 1 });
|
matched.set(x.aliasOf ?? x.name, { emoji: x, score: query.length + 2 });
|
||||||
}
|
}
|
||||||
return matched.size === max;
|
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) {
|
if (matched.size < max) {
|
||||||
emojiDb.some(x => {
|
emojiDb.some(x => {
|
||||||
|
|
|
@ -221,6 +221,22 @@ watch(q, () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
for (const emoji of emojis) {
|
||||||
|
if (emoji.name === newQ) {
|
||||||
|
matches.add(emoji);
|
||||||
|
if (matches.size >= max) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
for (const emoji of emojis) {
|
||||||
if (emoji.name.startsWith(newQ)) {
|
if (emoji.name.startsWith(newQ)) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
|
|
Loading…
Reference in New Issue