1
0
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:
Sami Mazouz 2023-04-24 17:57:41 +01:00 committed by GitHub
parent 7684a1086a
commit accdfde6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 4 deletions

View File

@ -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,

View File

@ -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';

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;
}