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

fix: undo when erasing elements by clicking (#4921)

* fix: undo when erasing elements by clicking

* newline remove
This commit is contained in:
Aakansha Doshi 2022-03-14 14:59:55 +05:30 committed by GitHub
parent 3aa0c5ebc0
commit 6d45430344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2999,25 +2999,6 @@ class App extends React.Component<AppProps, AppState> {
);
}
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<AppProps, AppState> {
// 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;
}