From 6d4543034406019a42a3ea5f1443ca2f61b972de Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Mon, 14 Mar 2022 14:59:55 +0530 Subject: [PATCH] fix: undo when erasing elements by clicking (#4921) * fix: undo when erasing elements by clicking * newline remove --- src/components/App.tsx | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index d80f6f8b..fa3682f7 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2999,25 +2999,6 @@ class App extends React.Component { ); } if (isEraserActive(this.state)) { - const draggedDistance = distance2d( - this.lastPointerDown!.clientX, - this.lastPointerDown!.clientY, - this.lastPointerUp!.clientX, - this.lastPointerUp!.clientY, - ); - 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 ( this.hitLinkElement && @@ -4422,6 +4403,28 @@ class App extends React.Component { // drag or added to selection on pointer down phase. const hitElement = pointerDownState.hit.element; if (isEraserActive(this.state)) { + const draggedDistance = distance2d( + this.lastPointerDown!.clientX, + this.lastPointerDown!.clientY, + this.lastPointerUp!.clientX, + this.lastPointerUp!.clientY, + ); + + if (draggedDistance === 0) { + const scenePointer = viewportCoordsToSceneCoords( + { + clientX: this.lastPointerUp!.clientX, + clientY: this.lastPointerUp!.clientY, + }, + this.state, + ); + const hitElement = this.getElementAtPosition( + scenePointer.x, + scenePointer.y, + ); + + pointerDownState.hit.element = hitElement; + } this.eraseElements(pointerDownState); return; }