From 5d2ef71d33bea9ba6bf1aeb3cceee08af27f1e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Sat, 4 Dec 2021 23:24:21 +0100 Subject: [PATCH] fix: call onExit hook when editor is destroyed, fix #1645 --- packages/suggestion/src/suggestion.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index b174b5d8..37a300a9 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -67,6 +67,7 @@ export function Suggestion({ allow = () => true, }: SuggestionOptions) { + let props: SuggestionProps | undefined const renderer = render?.() return new Plugin({ @@ -96,7 +97,8 @@ export function Suggestion({ ? prev : next const decorationNode = document.querySelector(`[data-decoration-id="${state.decorationId}"]`) - const props: SuggestionProps = { + + props = { editor, range: state.range, query: state.query, @@ -141,6 +143,14 @@ export function Suggestion({ renderer?.onStart?.(props) } }, + + destroy: () => { + if (!props) { + return + } + + renderer?.onExit?.(props) + }, } },