diff --git a/docs/api/utilities/suggestion.md b/docs/api/utilities/suggestion.md index 718efda5ab4..d0ecc4c7151 100644 --- a/docs/api/utilities/suggestion.md +++ b/docs/api/utilities/suggestion.md @@ -56,6 +56,14 @@ A render function for the autocomplete popup. Default: `() => ({})` +### findSuggestionMatch +Optional param to replace the built-in regex matching of editor content that triggers a suggestion. +See [the +source](https://github.com/estrattonbailey/tiptap/blob/develop/packages/suggestion/src/findSuggestionMatch.ts#L18) +for more detail. + +Default: `findSuggestionMatch(config: Trigger): SuggestionMatch` + ## Source code [packages/suggestion/](https://github.com/ueberdosis/tiptap/blob/main/packages/suggestion/) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index f75d24002c1..2823b910216 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -2,7 +2,7 @@ import { Editor, Range } from '@tiptap/core' import { EditorState, Plugin, PluginKey } from '@tiptap/pm/state' import { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view' -import { findSuggestionMatch } from './findSuggestionMatch.js' +import { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js' export interface SuggestionOptions { pluginKey?: PluginKey @@ -24,6 +24,7 @@ export interface SuggestionOptions { onKeyDown?: (props: SuggestionKeyDownProps) => boolean } allow?: (props: { editor: Editor; state: EditorState; range: Range }) => boolean + findSuggestionMatch?: typeof defaultFindSuggestionMatch } export interface SuggestionProps { @@ -58,6 +59,7 @@ export function Suggestion({ items = () => [], render = () => ({}), allow = () => true, + findSuggestionMatch = defaultFindSuggestionMatch, }: SuggestionOptions) { let props: SuggestionProps | undefined const renderer = render?.()