Skip to content

Commit e7a78ad

Browse files
committed
fix: add block below block with opened side menu
refs: #23
1 parent c10c10e commit e7a78ad

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

libs/ngx-blocknote/src/lib/components/side-menu/default-buttons/add-block-button/bna-add-block-button.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@ export class BnaAddBlockButtonComponent {
1717
constructor(public ngxBlockNoteService: NgxBlocknoteService) {}
1818

1919
addNewBlock() {
20-
const currentBlock = this.ngxBlockNoteService.editor().getTextCursorPosition().block;
21-
this.ngxBlockNoteService.editor().insertBlocks([{
22-
type: "paragraph",
23-
}], currentBlock, "after");
20+
const editor = this.ngxBlockNoteService.editor();
21+
const currentBlock = this.ngxBlockNoteService.sideMenuFocusedBlock();
22+
if (!currentBlock) return;
23+
const insertedBlock = this.ngxBlockNoteService.editor().insertBlocks(
24+
[
25+
{
26+
type: 'paragraph',
27+
},
28+
],
29+
currentBlock,
30+
'after',
31+
)[0];
32+
editor.setTextCursorPosition(insertedBlock);
33+
editor.openSuggestionMenu('/');
2434
}
2535
}

0 commit comments

Comments
 (0)