Skip to content

Commit b49520d

Browse files
committed
fix: use block from opened file panel
1 parent 8a344f4 commit b49520d

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

libs/ngx-blocknote/src/lib/components/file-panel/bna-file-panel.component.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, signal } from '@angular/core';
1+
import { Component, signal } from '@angular/core';
22
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
33
import {
44
BlockFromConfig,
@@ -30,7 +30,7 @@ import {
3030
],
3131
templateUrl: './bna-file-panel.component.html',
3232
})
33-
export class BnaFilePanelComponent implements OnInit {
33+
export class BnaFilePanelComponent {
3434
focusedBlock = signal<BlockFromConfig<FileBlockConfig, any, any> | undefined>(
3535
undefined,
3636
);
@@ -40,20 +40,20 @@ export class BnaFilePanelComponent implements OnInit {
4040

4141
constructor(private ngxBlockNoteService: NgxBlocknoteService) {
4242
const editor = this.ngxBlockNoteService.editor();
43-
editor.filePanel?.onUpdate(async (filePanelState) => {
44-
if (!filePanelState.show) {
45-
this.focusedBlock.set(undefined);
46-
} else {
47-
this.focusedBlock.set(filePanelState.block);
48-
}
49-
});
43+
if(editor.filePanel){
44+
//TODO: remove the workaround
45+
//Workaround use view state from file panel to get the block
46+
this.focusedBlock.set((editor.filePanel! as any).view.state.block)
47+
editor.filePanel.onUpdate(async (filePanelState) => {
48+
if (!filePanelState.show) {
49+
this.focusedBlock.set(undefined);
50+
} else {
51+
this.focusedBlock.set(filePanelState.block);
52+
}
53+
});
54+
}
5055
}
5156

52-
ngOnInit() {
53-
const editor = this.ngxBlockNoteService.editor();
54-
const block = editor.getTextCursorPosition().block;
55-
this.focusedBlock.set(block as any);
56-
}
5757

5858
async onFileInputChanged(event: Event) {
5959
const editor = this.ngxBlockNoteService.editor();

0 commit comments

Comments
 (0)