summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2020-11-07 21:28:28 +0900
committersyuilo <syuilotan@yahoo.co.jp>2020-11-07 21:28:28 +0900
commit80c490a18b5957052f729bcebbfa89fa89052290 (patch)
tree7d7772f3588d5164f5362e71f23961e9121764fa /src
parent12.54.0 (diff)
downloadmisskey-80c490a18b5957052f729bcebbfa89fa89052290.tar.gz
misskey-80c490a18b5957052f729bcebbfa89fa89052290.tar.bz2
misskey-80c490a18b5957052f729bcebbfa89fa89052290.zip
絵文字ピッカーでAND検索に対応
Diffstat (limited to 'src')
-rw-r--r--src/client/components/emoji-picker.vue132
1 files changed, 88 insertions, 44 deletions
diff --git a/src/client/components/emoji-picker.vue b/src/client/components/emoji-picker.vue
index 21d39e8e9e..e38206f140 100644
--- a/src/client/components/emoji-picker.vue
+++ b/src/client/components/emoji-picker.vue
@@ -190,36 +190,58 @@ export default defineComponent({
const exactMatch = emojis.find(e => e.name === q);
if (exactMatch) matches.add(exactMatch);
- for (const emoji of emojis) {
- if (emoji.name.startsWith(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ if (q.includes(' ')) { // AND検索
+ const keywords = q.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;
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.aliases.some(alias => alias.startsWith(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ // 名前またはエイリアスにキーワードが含まれている
+ 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;
+ }
}
- }
- if (matches.size >= max) return matches;
+ } else {
+ for (const emoji of emojis) {
+ if (emoji.name.startsWith(q)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.name.includes(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ for (const emoji of emojis) {
+ if (emoji.aliases.some(alias => alias.startsWith(q))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
}
- }
- if (matches.size >= max) return matches;
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.aliases.some(alias => alias.includes(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ for (const emoji of emojis) {
+ if (emoji.name.includes(q)) {
+ 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.includes(q))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
}
}
+
return matches;
};
@@ -231,36 +253,58 @@ export default defineComponent({
const exactMatch = emojis.find(e => e.name === q);
if (exactMatch) matches.add(exactMatch);
- for (const emoji of emojis) {
- if (emoji.name.startsWith(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ if (q.includes(' ')) { // AND検索
+ const keywords = q.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;
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.keywords.some(keyword => keyword.startsWith(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ // 名前またはエイリアスにキーワードが含まれている
+ for (const emoji of emojis) {
+ if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.keywords.some(alias => alias.includes(keyword)))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
}
- }
- if (matches.size >= max) return matches;
+ } else {
+ for (const emoji of emojis) {
+ if (emoji.name.startsWith(q)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.name.includes(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ for (const emoji of emojis) {
+ if (emoji.keywords.some(keyword => keyword.startsWith(q))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
}
- }
- if (matches.size >= max) return matches;
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.keywords.some(keyword => keyword.includes(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
+ for (const emoji of emojis) {
+ if (emoji.name.includes(q)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
+
+ for (const emoji of emojis) {
+ if (emoji.keywords.some(keyword => keyword.includes(q))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
}
}
+
return matches;
};