fix: call onExit hook when editor is destroyed, fix #1645
This commit is contained in:
@@ -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)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user