Skip to content

Commit

Permalink
fix: prevent floating menu flicker on click
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Feb 5, 2021
1 parent 3aee0ef commit 4617294
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/lib/modules/menu/floating-menu/floating-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class FloatingMenuComponent implements OnInit, OnDestroy {
private showMenu = false;
private updateSubscription: Subscription;
private dragging = false;
private clicked = false;
private resizeSubscription: Subscription;
execulableItems: TBItems[] = [];
activeItems: TBItems[] = [];
Expand Down Expand Up @@ -101,6 +102,15 @@ export class FloatingMenuComponent implements OnInit, OnDestroy {
return this.sanitizeHTML.transform(icon);
}

private hide(): void {
this.clicked = false;
this.showMenu = false;
}

private show(): void {
this.showMenu = true;
}

private calculateBubblePosition(view: EditorView): BubblePosition {
const { state: { selection } } = view;
const { from } = selection;
Expand Down Expand Up @@ -140,23 +150,26 @@ export class FloatingMenuComponent implements OnInit, OnDestroy {

if (selection instanceof NodeSelection) {
if (selection.node.type.name === 'image') {
this.showMenu = false;
this.hide();
return;
}
}

const hasFocus = this.view.hasFocus();

if (!hasFocus || empty || this.dragging) {
this.showMenu = false;
this.hide();
return;
}

const { bottom, left } = this.calculateBubblePosition(this.view);

this.posLeft = left;
this.posBottom = bottom;
this.showMenu = true;

if (!this.clicked) {
this.show();
}
}

onClick(e: MouseEvent, commandName: TBItems): void {
Expand All @@ -169,8 +182,7 @@ export class FloatingMenuComponent implements OnInit, OnDestroy {

const command = ToggleCommands[commandName];
command.toggle()(state, dispatch);

this.showMenu = false;
this.clicked = true;
}

private findActiveAndDisabledItems(view: EditorView): void {
Expand Down

0 comments on commit 4617294

Please sign in to comment.