aframevr / aframe-inspector

:mag: Visual inspector tool for A-Frame. Hit *<ctrl> + <alt> + i* on any A-Frame scene.
https://aframe.io/aframe-inspector/examples/
MIT License
647 stars 198 forks source link

Properly unregister listeners on canvas when closing inspector #683

Closed vincentfretin closed 1 year ago

vincentfretin commented 1 year ago

Properly unregister listeners on canvas (inspector.container) when closing inspector and register them back when opening again. I verified, enable function here is called only when reopening, not at inspector initialization. So we don't end up registering the listeners twice. Those are registered on inspector initialization here https://github.com/aframevr/aframe-inspector/blob/aecc85bcd2dde219fc272240bf8bfcd3ebf87b03/src/lib/raycaster.js#L46-L48

The issue was the event.preventDefault(); in onMouseDown here https://github.com/aframevr/aframe-inspector/blob/aecc85bcd2dde219fc272240bf8bfcd3ebf87b03/src/lib/raycaster.js#L87 This listener was still active when the inspector was closed prevented the focus logic on canvas to work properly. For example closing the inspector, clicking on some other buttons on a custom UI and back to canvas, document.activeElement didn't come back to document.body preventing usage of wasd controls. The issue was found in two different applications, see https://github.com/3DStreet/3dstreet-editor/issues/130 for context.