Skip to content

Commit

Permalink
feat: allow triggering suggestions without prefix space (#1826, fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosir authored Sep 6, 2021
1 parent a03aa2c commit 4dd0d6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/suggestion/src/findSuggestionMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ResolvedPos } from 'prosemirror-model'
export interface Trigger {
char: string,
allowSpaces: boolean,
prefixSpace: boolean,
startOfLine: boolean,
$position: ResolvedPos,
}
Expand All @@ -18,6 +19,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
const {
char,
allowSpaces,
prefixSpace,
startOfLine,
$position,
} = config
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface SuggestionOptions {
char?: string,
allowSpaces?: boolean,
startOfLine?: boolean,
prefixSpace?: boolean,
decorationTag?: string,
decorationClass?: string,
command?: (props: {
Expand Down Expand Up @@ -53,6 +54,7 @@ export function Suggestion({
editor,
char = '@',
allowSpaces = false,
prefixSpace = true,
startOfLine = false,
decorationTag = 'span',
decorationClass = 'suggestion',
Expand Down Expand Up @@ -173,6 +175,7 @@ export function Suggestion({
const match = findSuggestionMatch({
char,
allowSpaces,
prefixSpace,
startOfLine,
$position: selection.$from,
})
Expand Down

0 comments on commit 4dd0d6d

Please sign in to comment.