forked from AkkomaGang/akkoma-fe
Add mfm autocomplete (#183)
I thought it could be neat to have an autocomplete like Misskey has for MFM. A condition was removed that prevented autocomplete to actually autocomplete stuff when only the first character was entered. It doesn't affect the other autocompletes since none of them display their elements if nothing was actually searched. (in that case MFM returns the full list of elements) Co-authored-by: solidsanek <solidsanek@outerheaven.club> Reviewed-on: AkkomaGang/pleroma-fe#183 Reviewed-by: floatingghost <hannah@coffee-and-dreams.uk> Co-authored-by: solidsanek <solidsanek@noreply.akkoma> Co-committed-by: solidsanek <solidsanek@noreply.akkoma>
This commit is contained in:
parent
2e00c19074
commit
bda433b006
3 changed files with 9 additions and 3 deletions
|
@ -178,7 +178,7 @@ const EmojiInput = {
|
||||||
textAtCaret: async function (newWord) {
|
textAtCaret: async function (newWord) {
|
||||||
const firstchar = newWord.charAt(0)
|
const firstchar = newWord.charAt(0)
|
||||||
this.suggestions = []
|
this.suggestions = []
|
||||||
if (newWord === firstchar) return
|
if (newWord === firstchar && firstchar !== '$') return
|
||||||
const matchedSuggestions = await this.suggest(newWord)
|
const matchedSuggestions = await this.suggest(newWord)
|
||||||
// Async: cancel if textAtCaret has changed during wait
|
// Async: cancel if textAtCaret has changed during wait
|
||||||
if (this.textAtCaret !== newWord) return
|
if (this.textAtCaret !== newWord) return
|
||||||
|
@ -277,7 +277,6 @@ const EmojiInput = {
|
||||||
},
|
},
|
||||||
replaceText (e, suggestion) {
|
replaceText (e, suggestion) {
|
||||||
const len = this.suggestions.length || 0
|
const len = this.suggestions.length || 0
|
||||||
if (this.textAtCaret.length === 1) { return }
|
|
||||||
if (len > 0 || suggestion) {
|
if (len > 0 || suggestion) {
|
||||||
const chosenSuggestion = suggestion || this.suggestions[this.highlighted]
|
const chosenSuggestion = suggestion || this.suggestions[this.highlighted]
|
||||||
const replacement = chosenSuggestion.replacement
|
const replacement = chosenSuggestion.replacement
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
:class="{ highlighted: index === highlighted }"
|
:class="{ highlighted: index === highlighted }"
|
||||||
@click.stop.prevent="onClick($event, suggestion)"
|
@click.stop.prevent="onClick($event, suggestion)"
|
||||||
>
|
>
|
||||||
<span class="image">
|
<span v-if="!suggestion.mfm" class="image">
|
||||||
<img
|
<img
|
||||||
v-if="suggestion.img"
|
v-if="suggestion.img"
|
||||||
:src="suggestion.img"
|
:src="suggestion.img"
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
const MFM_TAGS = ['blur', 'bounce', 'flip', 'font', 'jelly', 'jump', 'rainbow', 'rotate', 'shake', 'sparkle', 'spin', 'tada', 'twitch', 'x2', 'x3', 'x4']
|
||||||
|
.map(tag => ({ displayText: tag, detailText: '$[' + tag + ' ]', replacement: '$[' + tag + ' ]', mfm: true }))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suggest - generates a suggestor function to be used by emoji-input
|
* suggest - generates a suggestor function to be used by emoji-input
|
||||||
* data: object providing source information for specific types of suggestions:
|
* data: object providing source information for specific types of suggestions:
|
||||||
|
@ -21,6 +24,10 @@ export default data => {
|
||||||
if (firstChar === '@' && usersCurry) {
|
if (firstChar === '@' && usersCurry) {
|
||||||
return usersCurry(input)
|
return usersCurry(input)
|
||||||
}
|
}
|
||||||
|
if (firstChar === '$') {
|
||||||
|
return MFM_TAGS
|
||||||
|
.filter(({ replacement }) => replacement.toLowerCase().indexOf(input) !== -1)
|
||||||
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue