Merge e2bde33dae
into 0884605b62
This commit is contained in:
commit
51697c81ef
|
@ -227,77 +227,37 @@ watch(q, () => {
|
||||||
const searchCustom = () => {
|
const searchCustom = () => {
|
||||||
const max = 100;
|
const max = 100;
|
||||||
const emojis = customEmojis.value;
|
const emojis = customEmojis.value;
|
||||||
const matches = new Set<Misskey.entities.EmojiSimple>();
|
const results: Misskey.entities.EmojiSimple[] = [];
|
||||||
|
const words = newQ.split(/\s+/);
|
||||||
|
|
||||||
const exactMatch = emojis.find(emoji => emoji.name === newQ);
|
let i = 0;
|
||||||
if (exactMatch) matches.add(exactMatch);
|
|
||||||
|
|
||||||
if (newQ.includes(' ')) { // AND検索
|
|
||||||
const keywords = newQ.split(' ');
|
|
||||||
|
|
||||||
// 名前にキーワードが含まれている
|
|
||||||
for (const emoji of emojis) {
|
|
||||||
if (keywords.every(keyword => emoji.name.includes(keyword))) {
|
|
||||||
matches.add(emoji);
|
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
// 名前またはエイリアスにキーワードが含まれている
|
|
||||||
for (const emoji of emojis) {
|
|
||||||
if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.aliases.some(alias => alias.includes(keyword)))) {
|
|
||||||
matches.add(emoji);
|
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (customEmojisMap.has(newQ)) {
|
|
||||||
matches.add(customEmojisMap.get(newQ)!);
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
for (const emoji of emojis) {
|
||||||
if (emoji.aliases.some(alias => alias === newQ)) {
|
if (i >= max) break;
|
||||||
matches.add(emoji);
|
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
const matching = words.slice();
|
||||||
if (emoji.name.startsWith(newQ)) {
|
for (const text of [emoji.name, ...emoji.aliases]) {
|
||||||
matches.add(emoji);
|
if (!matching.length) break;
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
for (let j = 0; j < matching.length; j++) {
|
||||||
if (emoji.aliases.some(alias => alias.startsWith(newQ))) {
|
if (text.toLowerCase().includes(matching[j])) {
|
||||||
matches.add(emoji);
|
matching.splice(j, 1);
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
j -= 1;
|
||||||
if (emoji.name.includes(newQ)) {
|
|
||||||
matches.add(emoji);
|
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (matches.size >= max) return matches;
|
|
||||||
|
|
||||||
for (const emoji of emojis) {
|
continue;
|
||||||
if (emoji.aliases.some(alias => alias.includes(newQ))) {
|
|
||||||
matches.add(emoji);
|
|
||||||
if (matches.size >= max) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches;
|
if (matching.length) continue;
|
||||||
|
|
||||||
|
results.push(emoji);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchUnicode = () => {
|
const searchUnicode = () => {
|
||||||
|
|
Loading…
Reference in New Issue