Skip to content

Commit 22688b1

Browse files
committed
fix: delete the row which has an opened side menu if its not in selected rows
1 parent 4793dc5 commit 22688b1

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

libs/block-note-angular/src/lib/components/bna-side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<button
2+
(click)="openDragMenu()"
23
(dragend)="dragEnd()"
34
[brnMenuTriggerFor]="menu"
45
(dragstart)="dragStart($event)"

libs/block-note-angular/src/lib/components/bna-side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,35 @@ import {
4141
export class BnaDragHandleMenuComponent implements OnChanges {
4242
editor = input.required<BlockNoteEditor>();
4343
dragMenuShown = false;
44-
focusedBlock?: Block;
44+
selectedBlocks: Block[] = [];
45+
dragBlock?: Block;
4546

4647
openDragMenu() {
47-
console.log('Open drag menu');
48+
const selection = this.editor().getSelection();
49+
//Todo: create type
50+
// Get the blocks in the current selection and store on the state. If
51+
// the selection is empty, store the block containing the text cursor
52+
// instead.
53+
let selectedBlocks: Block[] = [];
54+
if (selection !== undefined) {
55+
selectedBlocks = selection.blocks;
56+
} else {
57+
selectedBlocks = [this.editor().getTextCursorPosition().block];
58+
}
59+
if (
60+
this.dragBlock &&
61+
selectedBlocks.find(
62+
(selectedBlock) => this.dragBlock!.id === selectedBlock.id
63+
) === undefined
64+
) {
65+
selectedBlocks = [this.dragBlock];
66+
}
67+
this.selectedBlocks = selectedBlocks;
68+
console.log('Open drag menu', this.selectedBlocks);
4869
this.dragMenuShown = !this.dragMenuShown;
49-
// this.editor().block;
5070
if (this.dragMenuShown) {
5171
this.editor().sideMenu.freezeMenu();
5272
}
53-
// this.editor().removeBlocks([this.editor.name]);
5473
}
5574

5675
dragStart($event: DragEvent) {
@@ -66,29 +85,13 @@ export class BnaDragHandleMenuComponent implements OnChanges {
6685

6786
ngOnChanges() {
6887
this.editor().sideMenu.onUpdate((state) => {
69-
if (!state.show) {
70-
this.dragMenuShown = false;
71-
this.focusedBlock = undefined;
72-
} else {
73-
this.focusedBlock = state.block;
74-
}
88+
this.dragBlock = state.block;
7589
});
7690
}
7791

7892
deleteBlock() {
79-
const selection = this.editor().getSelection();
80-
//Todo: create type
81-
let selectedBlocks = [];
82-
// Get the blocks in the current selection and store on the state. If
83-
// the selection is empty, store the block containing the text cursor
84-
// instead.
85-
if (selection !== undefined) {
86-
selectedBlocks = selection.blocks;
87-
} else {
88-
selectedBlocks = [this.editor().getTextCursorPosition().block];
89-
}
90-
console.log('delete block', selectedBlocks);
91-
this.editor().removeBlocks(selectedBlocks);
93+
console.log('delete block', this.selectedBlocks);
94+
this.editor().removeBlocks(this.selectedBlocks);
9295
this.editor().sideMenu.unfreezeMenu();
9396
}
9497
}

0 commit comments

Comments
 (0)