Allow searching for uppercased letters in emoji picker
This commit is contained in:
parent
23533c1aaa
commit
fdd97dce7d
1 changed files with 24 additions and 16 deletions
|
|
@ -257,19 +257,27 @@ watch(q, () => {
|
||||||
|
|
||||||
const searchCustom = () => {
|
const searchCustom = () => {
|
||||||
const max = 16;
|
const max = 16;
|
||||||
const emojis = customEmojis;
|
const emojis: {
|
||||||
|
lowercased: string;
|
||||||
|
lowercasedAliases: string[];
|
||||||
|
emoji: Misskey.entities.CustomEmoji;
|
||||||
|
}[] = customEmojis.map(emoji => ({
|
||||||
|
lowercased: emoji.name.toLowerCase(),
|
||||||
|
lowercasedAliases: emoji.aliases.map(alias => alias.toLowerCase()),
|
||||||
|
emoji,
|
||||||
|
}));
|
||||||
const matches = new Set<Misskey.entities.CustomEmoji>();
|
const matches = new Set<Misskey.entities.CustomEmoji>();
|
||||||
|
|
||||||
const exactMatch = emojis.find((emoji) => emoji.name === newQ);
|
const exactMatch = emojis.find((emoji) => emoji.lowercased === newQ);
|
||||||
if (exactMatch) matches.add(exactMatch);
|
if (exactMatch) matches.add(exactMatch.emoji);
|
||||||
|
|
||||||
if (newQ.includes(" ")) {
|
if (newQ.includes(" ")) {
|
||||||
// AND検索
|
// AND検索
|
||||||
const keywords = newQ.split(" ");
|
const keywords = newQ.split(" ");
|
||||||
|
|
||||||
// 名前にキーワードが含まれている
|
// 名前にキーワードが含まれている
|
||||||
for (const emoji of emojis) {
|
for (const { emoji, lowercased } of emojis) {
|
||||||
if (keywords.every((keyword) => emoji.name.includes(keyword))) {
|
if (keywords.every((keyword) => lowercased.includes(keyword))) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
if (matches.size >= max) break;
|
if (matches.size >= max) break;
|
||||||
}
|
}
|
||||||
|
|
@ -277,12 +285,12 @@ watch(q, () => {
|
||||||
if (matches.size >= max) return matches;
|
if (matches.size >= max) return matches;
|
||||||
|
|
||||||
// 名前またはエイリアスにキーワードが含まれている
|
// 名前またはエイリアスにキーワードが含まれている
|
||||||
for (const emoji of emojis) {
|
for (const { lowercased, lowercasedAliases, emoji } of emojis) {
|
||||||
if (
|
if (
|
||||||
keywords.every(
|
keywords.every(
|
||||||
(keyword) =>
|
(keyword) =>
|
||||||
emoji.name.includes(keyword) ||
|
lowercased.includes(keyword) ||
|
||||||
emoji.aliases.some((alias) =>
|
lowercasedAliases.some((alias) =>
|
||||||
alias.includes(keyword),
|
alias.includes(keyword),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -292,32 +300,32 @@ watch(q, () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const emoji of emojis) {
|
for (const { lowercased, emoji } of emojis) {
|
||||||
if (emoji.name.startsWith(newQ)) {
|
if (lowercased.startsWith(newQ)) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
if (matches.size >= max) break;
|
if (matches.size >= max) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matches.size >= max) return matches;
|
if (matches.size >= max) return matches;
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
for (const { lowercasedAliases, emoji } of emojis) {
|
||||||
if (emoji.aliases.some((alias) => alias.startsWith(newQ))) {
|
if (lowercasedAliases.some((alias) => alias.startsWith(newQ))) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
if (matches.size >= max) break;
|
if (matches.size >= max) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matches.size >= max) return matches;
|
if (matches.size >= max) return matches;
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
for (const { lowercased, emoji } of emojis) {
|
||||||
if (emoji.name.includes(newQ)) {
|
if (lowercased.includes(newQ)) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
if (matches.size >= max) break;
|
if (matches.size >= max) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matches.size >= max) return matches;
|
if (matches.size >= max) return matches;
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
for (const { lowercasedAliases, emoji } of emojis) {
|
||||||
if (emoji.aliases.some((alias) => alias.includes(newQ))) {
|
if (lowercasedAliases.some((alias) => alias.includes(newQ))) {
|
||||||
matches.add(emoji);
|
matches.add(emoji);
|
||||||
if (matches.size >= max) break;
|
if (matches.size >= max) break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue