Virtual whiteboard for sketching hand-drawn like diagrams
fix: decouple actionFinalize and actionErase (#4984)
zsviczian734bb4d2ed3e
diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsxindex dd88c73ce3..8dc2c293c0 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 }) => (<ToolButtontype="button"diff --git a/src/actions/actionFinalize.tsx b/src/actions/actionFinalize.tsxindex 25d528bfa4..9f081600e1 100644--- a/src/actions/actionFinalize.tsx+++ b/src/actions/actionFinalize.tsx@@ -14,7 +14,6 @@ import {bindOrUnbindLinearElement,} from "../element/binding";import { isBindingElement } from "../element/typeChecks";-import { isEraserActive } from "../appState";export const actionFinalize = register({name: "finalize",@@ -146,7 +145,14 @@ export const actionFinalize = register({appState.activeTool.type === "freedraw") &&multiPointElement? appState.activeTool- : { ...appState.activeTool, type: "selection" },+ : {+ ...appState.activeTool,+ type:+ appState.activeTool.type === "eraser" &&+ appState.activeTool.lastActiveToolBeforeEraser+ ? appState.activeTool.lastActiveToolBeforeEraser+ : "selection",+ },draggingElement: null,multiElement: null,editingElement: null,@@ -167,12 +173,11 @@ export const actionFinalize = register({};},keyTest: (event, appState) =>- !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 }) => (<ToolButtontype="button"diff --git a/src/data/restore.ts b/src/data/restore.tsindex ea7ada2f1d..97f6f8a625 100644--- a/src/data/restore.ts+++ b/src/data/restore.ts@@ -252,9 +252,13 @@ export const restoreAppState = (}return {...nextAppState,- activeTool: AllowedExcalidrawActiveTools[nextAppState.activeTool.type]- ? nextAppState.activeTool- : { ...nextAppState.activeTool, type: "selection" },+ activeTool: {+ lastActiveToolBeforeEraser: null,+ locked: nextAppState.activeTool.locked ?? false,+ type: AllowedExcalidrawActiveTools[nextAppState.activeTool.type]+ ? nextAppState.activeTool.type ?? "selection"+ : "selection",+ },// Migrates from previous version where appState.zoom was a numberzoom:typeof appState.zoom === "number"diff --git a/src/tests/data/restore.test.ts b/src/tests/data/restore.test.tsindex 82878bee30..88647167ad 100644--- a/src/tests/data/restore.test.ts+++ b/src/tests/data/restore.test.ts@@ -310,7 +310,9 @@ describe("restoreAppState", () => {stubImportedAppState,stubLocalAppState,);- expect(restoredAppState.activeTool).toBe(stubImportedAppState.activeTool);+ expect(restoredAppState.activeTool).toEqual(+ stubImportedAppState.activeTool,+ );expect(restoredAppState.cursorButton).toBe(stubImportedAppState.cursorButton,);