diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-09-26 02:55:11 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-09-26 02:55:11 +0900 |
| commit | a70dbb7e74356caed2fe03bec05c4e8d5bde4316 (patch) | |
| tree | dc73cad17e4594f7ee3c04cca16f0bcc5f998a20 /src/client/scripts | |
| parent | refactor: fix types (diff) | |
| download | sharkey-a70dbb7e74356caed2fe03bec05c4e8d5bde4316.tar.gz sharkey-a70dbb7e74356caed2fe03bec05c4e8d5bde4316.tar.bz2 sharkey-a70dbb7e74356caed2fe03bec05c4e8d5bde4316.zip | |
feat(client): MFM関数構文のサジェストを実装
Diffstat (limited to 'src/client/scripts')
| -rw-r--r-- | src/client/scripts/autocomplete.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/client/scripts/autocomplete.ts b/src/client/scripts/autocomplete.ts index c4bcc4b724..e952ad3907 100644 --- a/src/client/scripts/autocomplete.ts +++ b/src/client/scripts/autocomplete.ts @@ -70,11 +70,13 @@ export class Autocomplete { const mentionIndex = text.lastIndexOf('@'); const hashtagIndex = text.lastIndexOf('#'); const emojiIndex = text.lastIndexOf(':'); + const mfmTagIndex = text.lastIndexOf('$'); const max = Math.max( mentionIndex, hashtagIndex, - emojiIndex); + emojiIndex, + mfmTagIndex); if (max == -1) { this.close(); @@ -83,6 +85,7 @@ export class Autocomplete { const isMention = mentionIndex != -1; const isHashtag = hashtagIndex != -1; + const isMfmTag = mfmTagIndex != -1; const isEmoji = emojiIndex != -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':'); let opened = false; @@ -114,6 +117,14 @@ export class Autocomplete { } } + if (isMfmTag && !opened) { + const mfmTag = text.substr(mfmTagIndex + 1); + if (!mfmTag.includes(' ')) { + this.open('mfmTag', mfmTag); + opened = true; + } + } + if (!opened) { this.close(); } @@ -244,6 +255,22 @@ export class Autocomplete { const pos = trimmedBefore.length + value.length; this.textarea.setSelectionRange(pos, pos); }); + } else if (type == 'mfmTag') { + const source = this.text; + + const before = source.substr(0, caret); + const trimmedBefore = before.substring(0, before.lastIndexOf('$')); + const after = source.substr(caret); + + // 挿入 + this.text = `${trimmedBefore}$[${value} ]${after}`; + + // キャレットを戻す + this.vm.$nextTick(() => { + this.textarea.focus(); + const pos = trimmedBefore.length + (value.length + 3); + this.textarea.setSelectionRange(pos, pos); + }); } } } |