Skip to content

Commit

Permalink
double tap eraser
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed May 23, 2024
1 parent a71bb63 commit 6ef88eb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ import {
actionRemoveAllElementsFromFrame,
actionSelectAllElementsInFrame,
} from "../actions/actionFrame";
import { actionToggleHandTool, zoomToFit } from "../actions/actionCanvas";
import {
actionToggleEraserTool,
actionToggleHandTool,
zoomToFit,
} from "../actions/actionCanvas";
import { jotaiStore } from "../jotai";
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
import { ImageSceneDataError } from "../errors";
Expand Down Expand Up @@ -4867,6 +4871,7 @@ class App extends React.Component<AppProps, AppState> {
});
};

private debounceDoubleClickTimestamp: number = 0;
private handleCanvasDoubleClick = (
event: React.MouseEvent<HTMLCanvasElement>,
) => {
Expand All @@ -4875,6 +4880,24 @@ class App extends React.Component<AppProps, AppState> {
if (this.state.multiElement) {
return;
}

const now = Date.now();
if (now - this.debounceDoubleClickTimestamp < 200) {
//handleCanvasDoubleClick click fires twice in case of touch.
//Once from the onTouchStart event handler, once from the double click event handler
return;
}
this.debounceDoubleClickTimestamp = now;

if (
this.state.penMode &&
this.lastPointerDownEvent?.pointerType === "touch" &&
this.state.activeTool.type !== "selection"
) {
this.updateScene(actionToggleEraserTool.perform([] as any, this.state));
return;
}

// we should only be able to double click when mode is selection
if (this.state.activeTool.type !== "selection") {
return;
Expand Down

0 comments on commit 6ef88eb

Please sign in to comment.