summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-08-12 12:41:57 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-08-12 12:41:57 +0900
commit0627df8116bcdf4814f2f643962b6544a8ce7602 (patch)
tree85eff4a378a3019169e17a1b0a0dce710cc2b77f /src
parentfix(client): 更新時にテーマキャッシュをクリアするように (diff)
downloadsharkey-0627df8116bcdf4814f2f643962b6544a8ce7602.tar.gz
sharkey-0627df8116bcdf4814f2f643962b6544a8ce7602.tar.bz2
sharkey-0627df8116bcdf4814f2f643962b6544a8ce7602.zip
improve(client): Improve emoji autocomplete
Diffstat (limited to 'src')
-rw-r--r--src/client/components/autocomplete.vue82
1 files changed, 43 insertions, 39 deletions
diff --git a/src/client/components/autocomplete.vue b/src/client/components/autocomplete.vue
index 35cfb77301..065ee6de2e 100644
--- a/src/client/components/autocomplete.vue
+++ b/src/client/components/autocomplete.vue
@@ -35,6 +35,7 @@ import { twemojiSvgBase } from '@/misc/twemoji-base';
import { getStaticImageUrl } from '@client/scripts/get-static-image-url';
import { acct } from '@client/filters/user';
import * as os from '@client/os';
+import { instance } from '@client/instance';
type EmojiDef = {
emoji: string;
@@ -75,6 +76,36 @@ for (const x of lib) {
emjdb.sort((a, b) => a.name.length - b.name.length);
+//#region Construct Emoji DB
+const customEmojis = instance.emojis;
+const emojiDefinitions: EmojiDef[] = [];
+
+for (const x of customEmojis) {
+ emojiDefinitions.push({
+ name: x.name,
+ emoji: `:${x.name}:`,
+ url: x.url,
+ isCustomEmoji: true
+ });
+
+ if (x.aliases) {
+ for (const alias of x.aliases) {
+ emojiDefinitions.push({
+ name: alias,
+ aliasOf: x.name,
+ emoji: `:${x.name}:`,
+ url: x.url,
+ isCustomEmoji: true
+ });
+ }
+ }
+}
+
+emojiDefinitions.sort((a, b) => a.name.length - b.name.length);
+
+const emojiDb = markRaw(emojiDefinitions.concat(emjdb));
+//#endregion
+
export default defineComponent({
props: {
type: {
@@ -124,7 +155,6 @@ export default defineComponent({
emojis: [],
items: [],
select: -1,
- emojiDb: [] as EmojiDef[]
}
},
@@ -144,36 +174,6 @@ export default defineComponent({
mounted() {
this.setPosition();
- //#region Construct Emoji DB
- const customEmojis = this.$instance.emojis;
- const emojiDefinitions: EmojiDef[] = [];
-
- for (const x of customEmojis) {
- emojiDefinitions.push({
- name: x.name,
- emoji: `:${x.name}:`,
- url: x.url,
- isCustomEmoji: true
- });
-
- if (x.aliases) {
- for (const alias of x.aliases) {
- emojiDefinitions.push({
- name: alias,
- aliasOf: x.name,
- emoji: `:${x.name}:`,
- url: x.url,
- isCustomEmoji: true
- });
- }
- }
- }
-
- emojiDefinitions.sort((a, b) => a.name.length - b.name.length);
-
- this.emojiDb = markRaw(emojiDefinitions.concat(emjdb));
- //#endregion
-
this.textarea.addEventListener('keydown', this.onKeydown);
for (const el of Array.from(document.querySelectorAll('body *'))) {
@@ -203,6 +203,13 @@ export default defineComponent({
complete(type, value) {
this.$emit('done', { type, value });
this.$emit('closed');
+
+ if (type === 'emoji') {
+ let recents = this.$store.state.recentlyUsedEmojis;
+ recents = recents.filter((e: any) => e !== value);
+ recents.unshift(value);
+ this.$store.set('recentlyUsedEmojis', recents.splice(0, 32));
+ }
},
setPosition() {
@@ -281,29 +288,26 @@ export default defineComponent({
}
} else if (this.type == 'emoji') {
if (this.q == null || this.q == '') {
- this.emojis = this.emojiDb.filter(x => x.isCustomEmoji && !x.aliasOf).sort((a, b) => {
- var textA = a.name.toUpperCase();
- var textB = b.name.toUpperCase();
- return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
- });
+ // 最近使った絵文字をサジェスト
+ this.emojis = this.$store.state.recentlyUsedEmojis.map(emoji => emojiDb.find(e => e.emoji == emoji)).filter(x => x != null);
return;
}
const matched = [];
const max = 30;
- this.emojiDb.some(x => {
+ emojiDb.some(x => {
if (x.name.startsWith(this.q) && !x.aliasOf && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
return matched.length == max;
});
if (matched.length < max) {
- this.emojiDb.some(x => {
+ emojiDb.some(x => {
if (x.name.startsWith(this.q) && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
return matched.length == max;
});
}
if (matched.length < max) {
- this.emojiDb.some(x => {
+ emojiDb.some(x => {
if (x.name.includes(this.q) && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
return matched.length == max;
});