X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/03490d6597dae4b50019b3087c517a783afaff81..refs/pull/5313/head:/resources/js/wysiwyg/utils/selection.ts diff --git a/resources/js/wysiwyg/utils/selection.ts b/resources/js/wysiwyg/utils/selection.ts index f1055d98a..67c2d91b2 100644 --- a/resources/js/wysiwyg/utils/selection.ts +++ b/resources/js/wysiwyg/utils/selection.ts @@ -82,8 +82,8 @@ export function $insertNewBlockNodeAtSelection(node: LexicalNode, insertAfter: b } export function $insertNewBlockNodesAtSelection(nodes: LexicalNode[], insertAfter: boolean = true) { - const selection = $getSelection(); - const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null; + const selectionNodes = $getSelection()?.getNodes() || []; + const blockElement = selectionNodes.length > 0 ? $getNearestNodeBlockParent(selectionNodes[0]) : null; if (blockElement) { if (insertAfter) {