From 5f1cd4591a6ba862df8370bc19e1a2dd9da00a5f Mon Sep 17 00:00:00 2001 From: David Luzar Date: Mon, 7 Feb 2022 13:20:19 +0100 Subject: [PATCH] fix: do not open links twice (#4738) --- src/components/App.tsx | 54 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index bb64d4b3c..1c60b8f73 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -416,7 +416,7 @@ class App extends React.Component { ref={this.handleCanvasRef} onContextMenu={this.handleCanvasContextMenu} onPointerMove={this.handleCanvasPointerMove} - onPointerUp={this.removePointer} + onPointerUp={this.handleCanvasPointerUp} onPointerCancel={this.removePointer} onTouchMove={this.handleTouchMove} onPointerDown={this.handleCanvasPointerDown} @@ -439,7 +439,7 @@ class App extends React.Component { onPointerDown={this.handleCanvasPointerDown} onDoubleClick={this.handleCanvasDoubleClick} onPointerMove={this.handleCanvasPointerMove} - onPointerUp={this.removePointer} + onPointerUp={this.handleCanvasPointerUp} onPointerCancel={this.removePointer} onTouchMove={this.handleTouchMove} > @@ -1523,28 +1523,6 @@ class App extends React.Component { }; removePointer = (event: React.PointerEvent | PointerEvent) => { - this.lastPointerUp = event; - if (this.isMobile) { - const scenePointer = viewportCoordsToSceneCoords( - { clientX: event.clientX, clientY: event.clientY }, - this.state, - ); - const hitElement = this.getElementAtPosition( - scenePointer.x, - scenePointer.y, - ); - this.hitLinkElement = this.getElementLinkAtPosition( - scenePointer, - hitElement, - ); - } - if ( - this.hitLinkElement && - !this.state.selectedElementIds[this.hitLinkElement.id] - ) { - this.redirectToLink(); - } - // remove touch handler for context menu on touch devices if (event.pointerType === "touch" && touchTimeout) { clearTimeout(touchTimeout); @@ -2879,6 +2857,34 @@ class App extends React.Component { } }; + private handleCanvasPointerUp = ( + event: React.PointerEvent, + ) => { + this.lastPointerUp = event; + if (this.isMobile) { + const scenePointer = viewportCoordsToSceneCoords( + { clientX: event.clientX, clientY: event.clientY }, + this.state, + ); + const hitElement = this.getElementAtPosition( + scenePointer.x, + scenePointer.y, + ); + this.hitLinkElement = this.getElementLinkAtPosition( + scenePointer, + hitElement, + ); + } + if ( + this.hitLinkElement && + !this.state.selectedElementIds[this.hitLinkElement.id] + ) { + this.redirectToLink(); + } + + this.removePointer(event); + }; + private maybeOpenContextMenuAfterPointerDownOnTouchDevices = ( event: React.PointerEvent, ): void => {