mirror of
https://github.com/flarum/core.git
synced 2025-07-15 13:56:23 +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:
@ -76,7 +76,10 @@ export default function addComposerAutocomplete() {
|
|||||||
if (absMentionStart) {
|
if (absMentionStart) {
|
||||||
const typed = lastChunk.substring(relMentionStart).toLowerCase();
|
const typed = lastChunk.substring(relMentionStart).toLowerCase();
|
||||||
matchTyped = activeFormat.queryFromTyped(typed);
|
matchTyped = activeFormat.queryFromTyped(typed);
|
||||||
mentionables.typed = matchTyped || typed;
|
|
||||||
|
if (!matchTyped) return;
|
||||||
|
|
||||||
|
mentionables.typed = matchTyped;
|
||||||
|
|
||||||
const buildSuggestions = () => {
|
const buildSuggestions = () => {
|
||||||
// If the user has started to type a mention,
|
// If the user has started to type a mention,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import MentionFormats from './MentionFormats';
|
|
||||||
import type MentionableModel from './MentionableModel';
|
import type MentionableModel from './MentionableModel';
|
||||||
import type Model from 'flarum/common/Model';
|
import type Model from 'flarum/common/Model';
|
||||||
import type Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
|
@ -13,7 +13,7 @@ export default class AtMentionFormat extends MentionFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public queryFromTyped(typed: string): string | null {
|
public queryFromTyped(typed: string): string | null {
|
||||||
const matchTyped = typed.match(/^["“]((?:(?!"#).)+)$/);
|
const matchTyped = typed.match(/^["“]?((?:(?!"#).)+)$/);
|
||||||
|
|
||||||
return matchTyped ? matchTyped[1] : null;
|
return matchTyped ? matchTyped[1] : null;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export default class HashMentionFormat extends MentionFormat {
|
|||||||
public queryFromTyped(typed: string): string | null {
|
public queryFromTyped(typed: string): string | null {
|
||||||
const matchTyped = typed.match(/^[-_\p{L}\p{N}\p{M}]+$/giu);
|
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 {
|
public format(slug: string): string {
|
||||||
|
@ -19,8 +19,19 @@ export default abstract class MentionFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract mentionables: (new (...args: any[]) => MentionableModel)[];
|
abstract mentionables: (new (...args: any[]) => MentionableModel)[];
|
||||||
|
|
||||||
protected abstract extendable: boolean;
|
protected abstract extendable: boolean;
|
||||||
|
|
||||||
abstract trigger(): string;
|
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 queryFromTyped(typed: string): string | null;
|
||||||
|
|
||||||
abstract format(...args: any): string;
|
abstract format(...args: any): string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user