1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-10 11:35:52 +01:00

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
This commit is contained in:
Aakansha Doshi 2022-03-22 17:14:07 +05:30 committed by GitHub
parent cded1cd63d
commit db28595302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4472,6 +4472,8 @@ class App extends React.Component<AppProps, AppState> {
}
this.eraseElements(pointerDownState);
return;
} else if (Object.keys(pointerDownState.elementIdsToErase).length) {
this.restoreReadyToEraseElements(pointerDownState);
}
if (
@ -4613,6 +4615,32 @@ class App extends React.Component<AppProps, AppState> {
});
}
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 (