From 734bb4d2ed3e7b1fac2f05cd5bca455d386bf4b9 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 29 Mar 2022 21:37:09 +0200 Subject: [PATCH] fix: decouple actionFinalize and actionErase (#4984) * Update actionCanvas.tsx * Update actionFinalize.tsx * lint * remove Escape trigger from actionErase * revert to lastActiveTool only if coming from eraser tool * unrelated: fix restoring `appState.activeTool` * one more restoring fix * fix tests Co-authored-by: dwelle --- src/actions/actionCanvas.tsx | 7 +------ src/actions/actionFinalize.tsx | 17 +++++++++++------ src/data/restore.ts | 10 +++++++--- src/tests/data/restore.test.ts | 4 +++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index dd88c73c..8dc2c293 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -323,12 +323,7 @@ export const actionErase = register({ commitToHistory: true, }; }, - keyTest: (event, appState) => { - return ( - event.key === KEYS.E || - (event.key === KEYS.ESCAPE && isEraserActive(appState)) - ); - }, + keyTest: (event) => event.key === KEYS.E, PanelComponent: ({ elements, appState, updateData, data }) => ( - !isEraserActive(appState) && - ((event.key === KEYS.ESCAPE && + (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 }) => ( { stubImportedAppState, stubLocalAppState, ); - expect(restoredAppState.activeTool).toBe(stubImportedAppState.activeTool); + expect(restoredAppState.activeTool).toEqual( + stubImportedAppState.activeTool, + ); expect(restoredAppState.cursorButton).toBe( stubImportedAppState.cursorButton, );