1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Added horizontal rule node

This commit is contained in:
Dan Brown
2024-06-27 15:48:06 +01:00
parent 72a0e081ca
commit 4e2820d6e3
5 changed files with 92 additions and 17 deletions

View File

@ -80,12 +80,16 @@ export function toggleSelectionBlockNodeType(editor: LexicalEditor, matcher: Lex
});
}
export function insertNewBlockNodeAtSelection(node: LexicalNode) {
export function insertNewBlockNodeAtSelection(node: LexicalNode, insertAfter: boolean = true) {
const selection = $getSelection();
const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
if (blockElement) {
blockElement.insertAfter(node);
if (insertAfter) {
blockElement.insertAfter(node);
} else {
blockElement.insertBefore(node);
}
} else {
$getRoot().append(node);
}