Skip to content

Commit

Permalink
Restore bounded listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bert committed Jan 15, 2024
1 parent 8279c90 commit 471002e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/web/tools/GestureHandlerWebDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export class GestureHandlerWebDelegate
private gestureHandler!: GestureHandler;
private eventManagers: EventManager<unknown>[] = [];

private boundDisableContextMenu: (e: MouseEvent) => void;
private boundEnableContextMenu: (e: MouseEvent) => void;

constructor() {
this.boundDisableContextMenu = this.disableContextMenu.bind(this);
this.boundEnableContextMenu = this.enableContextMenu.bind(this);
}

getView(): HTMLElement {
return this.view;
}
Expand Down Expand Up @@ -99,17 +107,20 @@ export class GestureHandlerWebDelegate

private addContextMenuListeners(config: Config): void {
if (this.shouldDisableContextMenu(config)) {
this.view.addEventListener('contextmenu', this.disableContextMenu);
this.view.addEventListener('contextmenu', this.boundDisableContextMenu);
} else if (config.enableContextMenu) {
this.view.addEventListener('contextmenu', this.enableContextMenu);
this.view.addEventListener('contextmenu', this.boundEnableContextMenu);
}
}

private removeContextMenuListeners(config: Config): void {
if (this.shouldDisableContextMenu(config)) {
this.view.removeEventListener('contextmenu', this.disableContextMenu);
this.view.removeEventListener(
'contextmenu',
this.boundDisableContextMenu
);
} else if (config.enableContextMenu) {
this.view.removeEventListener('contextmenu', this.enableContextMenu);
this.view.removeEventListener('contextmenu', this.boundEnableContextMenu);
}
}

Expand Down

0 comments on commit 471002e

Please sign in to comment.