Browse Source

fix: update cursorButton once freedraw is released (#4996)

Co-authored-by: dwelle <luzar.david@gmail.com>
Valerii Gusev 3 years ago
parent
commit
880e4feede

+ 2 - 0
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") &&

+ 1 - 0
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 ??

+ 3 - 3
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,

+ 3 - 9
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);
   });