mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-15 00:05:42 +01:00
Fix #2000
This commit is contained in:
parent
2c6f881093
commit
50a6efd568
1 changed files with 12 additions and 12 deletions
|
@ -69,25 +69,25 @@ class Autocomplete {
|
||||||
*/
|
*/
|
||||||
private onInput() {
|
private onInput() {
|
||||||
const caretPos = this.textarea.selectionStart;
|
const caretPos = this.textarea.selectionStart;
|
||||||
const text = this.text.substr(0, caretPos);
|
const text = this.text.substr(0, caretPos).split('\n').pop();
|
||||||
|
|
||||||
const mentionIndex = text.lastIndexOf('@');
|
const mentionIndex = text.lastIndexOf('@');
|
||||||
const hashtagIndex = text.lastIndexOf('#');
|
const hashtagIndex = text.lastIndexOf('#');
|
||||||
const emojiIndex = text.lastIndexOf(':');
|
const emojiIndex = text.lastIndexOf(':');
|
||||||
|
|
||||||
const start = Math.min(
|
const max = Math.max(
|
||||||
mentionIndex == -1 ? Infinity : mentionIndex,
|
mentionIndex,
|
||||||
hashtagIndex == -1 ? Infinity : hashtagIndex,
|
hashtagIndex,
|
||||||
emojiIndex == -1 ? Infinity : emojiIndex);
|
emojiIndex);
|
||||||
|
|
||||||
if (start == Infinity) {
|
if (max == -1) {
|
||||||
this.close();
|
this.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isMention = mentionIndex == start;
|
const isMention = mentionIndex != -1;
|
||||||
const isHashtag = hashtagIndex == start;
|
const isHashtag = hashtagIndex != -1;
|
||||||
const isEmoji = emojiIndex == start;
|
const isEmoji = emojiIndex != -1;
|
||||||
|
|
||||||
let opened = false;
|
let opened = false;
|
||||||
|
|
||||||
|
@ -99,15 +99,15 @@ class Autocomplete {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHashtag || opened == false) {
|
if (isHashtag && opened == false) {
|
||||||
const hashtag = text.substr(hashtagIndex + 1);
|
const hashtag = text.substr(hashtagIndex + 1);
|
||||||
if (!hashtag.includes(' ') && !hashtag.includes('\n')) {
|
if (!hashtag.includes(' ')) {
|
||||||
this.open('hashtag', hashtag);
|
this.open('hashtag', hashtag);
|
||||||
opened = true;
|
opened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmoji || opened == false) {
|
if (isEmoji && opened == false) {
|
||||||
const emoji = text.substr(emojiIndex + 1);
|
const emoji = text.substr(emojiIndex + 1);
|
||||||
if (emoji != '' && emoji.match(/^[\+\-a-z0-9_]+$/)) {
|
if (emoji != '' && emoji.match(/^[\+\-a-z0-9_]+$/)) {
|
||||||
this.open('emoji', emoji);
|
this.open('emoji', emoji);
|
||||||
|
|
Loading…
Reference in a new issue