From dbad8a48cbfbb0d9a5461220ab76bfff18350448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Ko=C5=A1ir?= Date: Wed, 1 Sep 2021 20:49:22 +0200 Subject: [PATCH] Allow triggering suggestions without prefix space --- packages/suggestion/src/findSuggestionMatch.ts | 4 +++- packages/suggestion/src/suggestion.ts | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/suggestion/src/findSuggestionMatch.ts b/packages/suggestion/src/findSuggestionMatch.ts index f824c24aec0..fcbc20878f2 100644 --- a/packages/suggestion/src/findSuggestionMatch.ts +++ b/packages/suggestion/src/findSuggestionMatch.ts @@ -4,6 +4,7 @@ import { ResolvedPos } from 'prosemirror-model' export interface Trigger { char: string, allowSpaces: boolean, + prefixSpace: boolean, startOfLine: boolean, $position: ResolvedPos, } @@ -18,6 +19,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch { const { char, allowSpaces, + prefixSpace, startOfLine, $position, } = config @@ -49,7 +51,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch { // or the line beginning const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index) - if (!/^[\s\0]?$/.test(matchPrefix)) { + if (prefixSpace && !/^[\s\0]?$/.test(matchPrefix)) { return null } diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 819ca945acd..154b456c230 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -9,6 +9,7 @@ export interface SuggestionOptions { char?: string, allowSpaces?: boolean, startOfLine?: boolean, + prefixSpace?: boolean, decorationTag?: string, decorationClass?: string, command?: (props: { @@ -53,6 +54,7 @@ export function Suggestion({ editor, char = '@', allowSpaces = false, + prefixSpace = true, startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', @@ -173,6 +175,7 @@ export function Suggestion({ const match = findSuggestionMatch({ char, allowSpaces, + prefixSpace, startOfLine, $position: selection.$from, })