double tap eraser

This commit is contained in:
zsviczian 2024-05-23 17:37:08 +00:00
parent a71bb63d1f
commit 6ef88eb851

View File

@ -370,7 +370,11 @@ import {
actionRemoveAllElementsFromFrame, actionRemoveAllElementsFromFrame,
actionSelectAllElementsInFrame, actionSelectAllElementsInFrame,
} from "../actions/actionFrame"; } from "../actions/actionFrame";
import { actionToggleHandTool, zoomToFit } from "../actions/actionCanvas"; import {
actionToggleEraserTool,
actionToggleHandTool,
zoomToFit,
} from "../actions/actionCanvas";
import { jotaiStore } from "../jotai"; import { jotaiStore } from "../jotai";
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog"; import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
import { ImageSceneDataError } from "../errors"; import { ImageSceneDataError } from "../errors";
@ -4867,6 +4871,7 @@ class App extends React.Component<AppProps, AppState> {
}); });
}; };
private debounceDoubleClickTimestamp: number = 0;
private handleCanvasDoubleClick = ( private handleCanvasDoubleClick = (
event: React.MouseEvent<HTMLCanvasElement>, event: React.MouseEvent<HTMLCanvasElement>,
) => { ) => {
@ -4875,6 +4880,24 @@ class App extends React.Component<AppProps, AppState> {
if (this.state.multiElement) { if (this.state.multiElement) {
return; 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 // we should only be able to double click when mode is selection
if (this.state.activeTool.type !== "selection") { if (this.state.activeTool.type !== "selection") {
return; return;