From e92d1339732b8d5119ba8232fc904b0cbe7f0c0a Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Fri, 11 Mar 2022 20:44:17 +0530 Subject: [PATCH] fix: undo when erasing (#4900) --- src/components/App.tsx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 9966bc69..d80f6f8b 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2999,22 +2999,24 @@ class App extends React.Component { ); } if (isEraserActive(this.state)) { - const scenePointer = viewportCoordsToSceneCoords( - { clientX: event.clientX, clientY: event.clientY }, - this.state, + const draggedDistance = distance2d( + this.lastPointerDown!.clientX, + this.lastPointerDown!.clientY, + this.lastPointerUp!.clientX, + this.lastPointerUp!.clientY, ); - const hitElement = this.getElementAtPosition( - scenePointer.x, - scenePointer.y, - ); - const pointerDownEvent = this.initialPointerDownState(event); - pointerDownEvent.hit.element = hitElement; - this.eraseElements(pointerDownEvent); - if (isTouchScreen) { - this.hitLinkElement = this.getElementLinkAtPosition( - scenePointer, - hitElement, + if (draggedDistance === 0) { + const scenePointer = viewportCoordsToSceneCoords( + { clientX: event.clientX, clientY: event.clientY }, + this.state, ); + const hitElement = this.getElementAtPosition( + scenePointer.x, + scenePointer.y, + ); + const pointerDownEvent = this.initialPointerDownState(event); + pointerDownEvent.hit.element = hitElement; + this.eraseElements(pointerDownEvent); } } if (