From 1331cffe93ffec7e94670b3d95e3e3c1bd228c57 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Mon, 28 Mar 2022 21:33:32 +0200 Subject: [PATCH] feat: Eraser toggle to switch back to the previous tool (#4981) * add typeBeforeEraser * ESC to switch to lastActiveToolBeforeEraser --- src/actions/actionCanvas.tsx | 17 +++++++++++++++-- src/actions/actionFinalize.tsx | 8 +++++--- src/types.ts | 5 ++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 5ad42574f..b83bf6791 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -310,12 +310,25 @@ export const actionErase = register({ ...appState, selectedElementIds: {}, selectedGroupIds: {}, - activeTool: { type: isEraserActive(appState) ? "selection" : "eraser" }, + activeTool: { + type: isEraserActive(appState) + ? appState.activeTool.lastActiveToolBeforeEraser ?? "selection" + : "eraser", + lastActiveToolBeforeEraser: + appState.activeTool.type === "eraser" //node throws incorrect type error when using isEraserActive() + ? undefined + : appState.activeTool.type, + }, }, commitToHistory: true, }; }, - keyTest: (event) => event.key === KEYS.E, + keyTest: (event, appState) => { + return ( + event.key === KEYS.E || + (event.key === KEYS.ESCAPE && isEraserActive(appState)) + ); + }, PanelComponent: ({ elements, appState, updateData, data }) => ( - (event.key === KEYS.ESCAPE && + !isEraserActive(appState) && + ((event.key === KEYS.ESCAPE && (appState.editingLinearElement !== null || (!appState.draggingElement && appState.multiElement === null))) || - ((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) && - appState.multiElement !== null), + ((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) && + appState.multiElement !== null)), PanelComponent: ({ appState, updateData, data }) => (