Skip to content

Commit

Permalink
fix: suggestion menu click add the block and focuses it
Browse files Browse the repository at this point in the history
  • Loading branch information
m-risto committed Sep 16, 2024
1 parent dc1aa87 commit 0933db4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export class BnaSuggestionsMenuComponent implements OnChanges {
};

insertSelectedBlock() {
this.ngxBlockNoteService.editor().suggestionMenus.closeMenu();
this.ngxBlockNoteService.editor().suggestionMenus.clearQuery();
const editor = this.ngxBlockNoteService.editor();
editor.suggestionMenus.closeMenu();
editor.suggestionMenus.clearQuery();
this.filteredSlashMenuItems[this.selectedIndex].onItemClick();
this.selectedIndex = 0;
}
Expand All @@ -75,7 +76,7 @@ export class BnaSuggestionsMenuComponent implements OnChanges {
effect(() => {
this.filteredSlashMenuItems = filterSuggestionItems(
this.getSlashMenuItems(),
this.query()
this.query(),
);
});
}
Expand All @@ -92,6 +93,7 @@ export class BnaSuggestionsMenuComponent implements OnChanges {
this.selectedIndex = 0;
}
if (this.isShown() !== state.show) {
this.selectedIndex = 0;
this.isShown.set(state.show);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
type="button"
class="flex w-full justify-start py-1 px-4 h-full gap-4 text-left font-normal"
[ngClass]="{ 'bg-muted': selected() }"
(click)="onClick()"
(mousedown)="onClick($event)"
(mouseenter)="onMouseEnter()"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ export class BnaSuggestionMenuItemComponent {
if (!item) {
return 'lucideLayoutPanelTop';
}
const icon = icons[item?.key];
const icon = icons[item.key];
return icon ? icon : 'lucideLayoutPanelTop';
});
selected = input<boolean>(false);
mouseEnter = output();

constructor(private ngxBlockNoteService: NgxBlocknoteService) {}

onClick() {
this.ngxBlockNoteService.editor().suggestionMenus.clearQuery();
onClick($event: Event) {
$event.preventDefault();
const editor = this.ngxBlockNoteService.editor();
editor.suggestionMenus.clearQuery();
this.suggestionItem().onItemClick();
this.ngxBlockNoteService.editor().suggestionMenus.closeMenu();
editor.suggestionMenus.closeMenu();
editor.focus();
}

onMouseEnter() {
Expand Down

0 comments on commit 0933db4

Please sign in to comment.