fix: add verification before invoking collapseToEnd function to avoid error (when selection don't exist)

This commit is contained in:
Bruno DA SILVA 2024-11-30 11:48:44 +01:00
parent 01547d5b2f
commit 422c182290

View File

@ -122,7 +122,11 @@ export const Mention = Node.create<MentionOptions>({
.run()
// get reference to `window` object from editor element, to support cross-frame JS usage
editor.view.dom.ownerDocument.defaultView?.getSelection()?.collapseToEnd()
const selection = editor.view.dom.ownerDocument.defaultView?.getSelection()
if (selection && selection.rangeCount > 0) {
selection.collapseToEnd()
}
},
allow: ({ state, range }) => {
const $from = state.doc.resolve(range.from)