feat: Eraser toggle to switch back to the previous tool (#4981)

* add typeBeforeEraser

* ESC to switch to lastActiveToolBeforeEraser
This commit is contained in:
zsviczian 2022-03-28 21:33:32 +02:00 committed by GitHub
parent f242721f3b
commit 1331cffe93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View file

@ -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 }) => (
<ToolButton
type="button"