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,
}: 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)
},
}
},