Skip to content

Commit

Permalink
fix(FirstPersonControls): prevent context menu from poping
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Oct 6, 2021
1 parent 04b8806 commit 94bfd57
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Controls/FirstPersonControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ class FirstPersonControls extends THREE.EventDispatcher {
this._onMouseWheel = this.onMouseWheel.bind(this);
this._onKeyUp = this.onKeyUp.bind(this);
this._onKeyDown = this.onKeyDown.bind(this);
this._onContextMenu = this.onContextMenu.bind(this);
view.domElement.addEventListener('mousedown', this._onMouseDown, false);
view.domElement.addEventListener('touchstart', this._onMouseDown, false);
view.domElement.addEventListener('mousemove', this._onMouseMove, false);
view.domElement.addEventListener('touchmove', this._onMouseMove, false);
view.domElement.addEventListener('mouseup', this._onMouseUp, false);
view.domElement.addEventListener('touchend', this._onMouseUp, false);
view.domElement.addEventListener('wheel', this._onMouseWheel, false);
// Disable context menu when right clicking.
view.domElement.addEventListener('contextmenu', this._onContextMenu, false);

// TODO: Why windows
document.addEventListener('keydown', this._onKeyDown, false);
Expand Down Expand Up @@ -280,6 +283,10 @@ class FirstPersonControls extends THREE.EventDispatcher {
}
}

onContextMenu(event) {
event.preventDefault();
}

dispose() {
if (!this.eventListeners) {
this.view.domElement.removeEventListener('mousedown', this._onMouseDown, false);
Expand All @@ -289,6 +296,7 @@ class FirstPersonControls extends THREE.EventDispatcher {
this.view.domElement.removeEventListener('mouseup', this._onMouseUp, false);
this.view.domElement.removeEventListener('touchend', this._onMouseUp, false);
this.view.domElement.removeEventListener('wheel', this._onMouseWheel, false);
this.view.domElement.removeEventListener('contextmenu', this._onContextMenu, false);

document.removeEventListener('keydown', this._onKeyDown, false);
document.removeEventListener('keyup', this._onKeyUp, false);
Expand Down

0 comments on commit 94bfd57

Please sign in to comment.