From 880e4feedebab16c6265de97cb8073497f3a23fd Mon Sep 17 00:00:00 2001 From: Valerii Gusev Date: Fri, 1 Apr 2022 17:25:21 +0100 Subject: [PATCH] fix: update cursorButton once freedraw is released (#4996) Co-authored-by: dwelle --- src/actions/actionFinalize.tsx | 2 ++ src/data/restore.ts | 1 + .../__snapshots__/regressionTests.test.tsx.snap | 6 +++--- src/tests/data/restore.test.ts | 12 +++--------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/actions/actionFinalize.tsx b/src/actions/actionFinalize.tsx index 9f081600..4a777220 100644 --- a/src/actions/actionFinalize.tsx +++ b/src/actions/actionFinalize.tsx @@ -39,6 +39,7 @@ export const actionFinalize = register({ : undefined, appState: { ...appState, + cursorButton: "up", editingLinearElement: null, }, commitToHistory: true, @@ -140,6 +141,7 @@ export const actionFinalize = register({ elements: newElements, appState: { ...appState, + cursorButton: "up", activeTool: (appState.activeTool.locked || appState.activeTool.type === "freedraw") && diff --git a/src/data/restore.ts b/src/data/restore.ts index 421223ef..51954487 100644 --- a/src/data/restore.ts +++ b/src/data/restore.ts @@ -252,6 +252,7 @@ export const restoreAppState = ( } return { ...nextAppState, + cursorButton: localAppState?.cursorButton || "up", // reset on fresh restore so as to hide the UI button if penMode not active penDetected: localAppState?.penDetected ?? diff --git a/src/tests/__snapshots__/regressionTests.test.tsx.snap b/src/tests/__snapshots__/regressionTests.test.tsx.snap index e6ef53c1..9b22aab3 100644 --- a/src/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/src/tests/__snapshots__/regressionTests.test.tsx.snap @@ -6729,7 +6729,7 @@ Object { "currentItemStrokeStyle": "solid", "currentItemStrokeWidth": 1, "currentItemTextAlign": "left", - "cursorButton": "down", + "cursorButton": "up", "draggingElement": null, "editingElement": null, "editingGroupId": null, @@ -11029,7 +11029,7 @@ Object { "currentItemStrokeStyle": "solid", "currentItemStrokeWidth": 1, "currentItemTextAlign": "left", - "cursorButton": "down", + "cursorButton": "up", "draggingElement": null, "editingElement": null, "editingGroupId": null, @@ -12181,7 +12181,7 @@ Object { "currentItemStrokeStyle": "solid", "currentItemStrokeWidth": 1, "currentItemTextAlign": "left", - "cursorButton": "down", + "cursorButton": "up", "draggingElement": null, "editingElement": null, "editingGroupId": null, diff --git a/src/tests/data/restore.test.ts b/src/tests/data/restore.test.ts index 88647167..3ce03e58 100644 --- a/src/tests/data/restore.test.ts +++ b/src/tests/data/restore.test.ts @@ -313,9 +313,7 @@ describe("restoreAppState", () => { expect(restoredAppState.activeTool).toEqual( stubImportedAppState.activeTool, ); - expect(restoredAppState.cursorButton).toBe( - stubImportedAppState.cursorButton, - ); + expect(restoredAppState.cursorButton).toBe("up"); expect(restoredAppState.name).toBe(stubImportedAppState.name); }); @@ -347,9 +345,7 @@ describe("restoreAppState", () => { stubImportedAppState, null, ); - expect(restoredAppState.cursorButton).toBe( - stubImportedAppState.cursorButton, - ); + expect(restoredAppState.cursorButton).toBe("up"); expect(restoredAppState.name).toBe(stubImportedAppState.name); }); @@ -502,9 +498,7 @@ describe("restore", () => { importedDataState.appState = stubImportedAppState; const restoredData = restore.restore(importedDataState, null, null); - expect(restoredData.appState.cursorButton).toBe( - stubImportedAppState.cursorButton, - ); + expect(restoredData.appState.cursorButton).toBe("up"); expect(restoredData.appState.name).toBe(stubImportedAppState.name); });