From db2859530241bf188a06cb55d28eb9980a5bcef5 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 22 Mar 2022 17:14:07 +0530 Subject: [PATCH] fix: cancel erase elements on pointer up if eraser is not active on pointer up (#4956) * fix: erase elements on pointer up if present * cancel erase on pointer up if eraser is not active --- src/components/App.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/App.tsx b/src/components/App.tsx index fd27440a8..cec088fd0 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -4472,6 +4472,8 @@ class App extends React.Component { } this.eraseElements(pointerDownState); return; + } else if (Object.keys(pointerDownState.elementIdsToErase).length) { + this.restoreReadyToEraseElements(pointerDownState); } if ( @@ -4613,6 +4615,32 @@ class App extends React.Component { }); } + private restoreReadyToEraseElements = ( + pointerDownState: PointerDownState, + ) => { + const elements = this.scene.getElements().map((ele) => { + if ( + pointerDownState.elementIdsToErase[ele.id] && + pointerDownState.elementIdsToErase[ele.id].erase + ) { + return newElementWith(ele, { + opacity: pointerDownState.elementIdsToErase[ele.id].opacity, + }); + } else if ( + isBoundToContainer(ele) && + pointerDownState.elementIdsToErase[ele.containerId] && + pointerDownState.elementIdsToErase[ele.containerId].erase + ) { + return newElementWith(ele, { + opacity: pointerDownState.elementIdsToErase[ele.containerId].opacity, + }); + } + return ele; + }); + + this.scene.replaceAllElements(elements); + }; + private eraseElements = (pointerDownState: PointerDownState) => { const elements = this.scene.getElements().map((ele) => { if (