fix: call onExit hook when editor is destroyed, fix #1645

This commit is contained in:
Philipp Kühn
2021-12-04 23:24:21 +01:00
parent 80c2f85838
commit 5d2ef71d33

View File

@@ -67,6 +67,7 @@ export function Suggestion({
allow = () => true, allow = () => true,
}: SuggestionOptions) { }: SuggestionOptions) {
let props: SuggestionProps | undefined
const renderer = render?.() const renderer = render?.()
return new Plugin({ return new Plugin({
@@ -96,7 +97,8 @@ export function Suggestion({
? prev ? prev
: next : next
const decorationNode = document.querySelector(`[data-decoration-id="${state.decorationId}"]`) const decorationNode = document.querySelector(`[data-decoration-id="${state.decorationId}"]`)
const props: SuggestionProps = {
props = {
editor, editor,
range: state.range, range: state.range,
query: state.query, query: state.query,
@@ -141,6 +143,14 @@ export function Suggestion({
renderer?.onStart?.(props) renderer?.onStart?.(props)
} }
}, },
destroy: () => {
if (!props) {
return
}
renderer?.onExit?.(props)
},
} }
}, },