mirror of
https://github.com/flarum/core.git
synced 2025-04-22 08:06:15 +02:00
fix(mentions): mentions XHR fired even after mentioning is done (#3806)
* fix(mentions): mentions XHR fired even after mentioning is done Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: simplify diff Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
parent
7684a1086a
commit
accdfde6e1
@ -76,7 +76,10 @@ export default function addComposerAutocomplete() {
|
||||
if (absMentionStart) {
|
||||
const typed = lastChunk.substring(relMentionStart).toLowerCase();
|
||||
matchTyped = activeFormat.queryFromTyped(typed);
|
||||
mentionables.typed = matchTyped || typed;
|
||||
|
||||
if (!matchTyped) return;
|
||||
|
||||
mentionables.typed = matchTyped;
|
||||
|
||||
const buildSuggestions = () => {
|
||||
// If the user has started to type a mention,
|
||||
|
@ -1,4 +1,3 @@
|
||||
import MentionFormats from './MentionFormats';
|
||||
import type MentionableModel from './MentionableModel';
|
||||
import type Model from 'flarum/common/Model';
|
||||
import type Mithril from 'mithril';
|
||||
|
@ -13,7 +13,7 @@ export default class AtMentionFormat extends MentionFormat {
|
||||
}
|
||||
|
||||
public queryFromTyped(typed: string): string | null {
|
||||
const matchTyped = typed.match(/^["“]((?:(?!"#).)+)$/);
|
||||
const matchTyped = typed.match(/^["“]?((?:(?!"#).)+)$/);
|
||||
|
||||
return matchTyped ? matchTyped[1] : null;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export default class HashMentionFormat extends MentionFormat {
|
||||
public queryFromTyped(typed: string): string | null {
|
||||
const matchTyped = typed.match(/^[-_\p{L}\p{N}\p{M}]+$/giu);
|
||||
|
||||
return matchTyped ? matchTyped[1] : null;
|
||||
return matchTyped ? matchTyped[0] : null;
|
||||
}
|
||||
|
||||
public format(slug: string): string {
|
||||
|
@ -19,8 +19,19 @@ export default abstract class MentionFormat {
|
||||
}
|
||||
|
||||
abstract mentionables: (new (...args: any[]) => MentionableModel)[];
|
||||
|
||||
protected abstract extendable: boolean;
|
||||
|
||||
abstract trigger(): string;
|
||||
|
||||
/**
|
||||
* Picks the term to search in the API from the typed text.
|
||||
* @example:
|
||||
* * Full text = `Hello @"John D`
|
||||
* * Typed text = `"John D`
|
||||
* * Query = `John D`
|
||||
*/
|
||||
abstract queryFromTyped(typed: string): string | null;
|
||||
|
||||
abstract format(...args: any): string;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user