From ba0d3791010003e72b0c266c0450cac2af7ffc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 20 Jan 2021 09:23:44 +0100 Subject: [PATCH] add editor to suggestion command props --- packages/extension-mention/src/mention.ts | 16 ++++++++-------- packages/suggestion/src/suggestion.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index a7412c2c..c5e2cd94 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -15,6 +15,14 @@ export const Mention = Node.create({ HTMLAttributes: {}, suggestionOptions: { char: '@', + command: ({ editor, range, attributes }) => { + editor + .chain() + .focus() + .replace(range, 'mention', attributes) + .insertText(' ') + .run() + }, }, }, @@ -69,14 +77,6 @@ export const Mention = Node.create({ Suggestion({ editor: this.editor, ...this.options.suggestionOptions, - command: ({ range, attributes }) => { - this.editor - .chain() - .focus() - .replace(range, 'mention', attributes) - .insertText(' ') - .run() - }, }), ] }, diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 685bf898..c9120139 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -9,7 +9,11 @@ export interface SuggestionOptions { allowSpaces?: boolean, startOfLine?: boolean, suggestionClass?: string, - command?: (props: { range: Range, attributes: AnyObject }) => void, + command?: (props: { + editor: Editor, + range: Range, + attributes: AnyObject + }) => void, items?: (query: string) => any[], render?: () => { onStart?: (props: SuggestionProps) => void, @@ -83,7 +87,11 @@ export function Suggestion({ ? await items(state.query) : [], command: attributes => { - command({ range: state.range, attributes }) + command({ + editor, + range: state.range, + attributes, + }) }, decorationNode, // virtual node for popper.js or tippy.js