From c32640d1745db40ef985abf132323f6a24ca2d7f Mon Sep 17 00:00:00 2001 From: fujimoto kyosuke <31386431+lusingander@users.noreply.github.com> Date: Thu, 14 May 2020 21:32:10 +0900 Subject: [PATCH] Fix free draw to allow undo (#1594) --- src/components/App.tsx | 1 + .../regressionTests.test.tsx.snap | 276 +++++++++++++++++- 2 files changed, 275 insertions(+), 2 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index bc1aa50d..8ccf60ba 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2340,6 +2340,7 @@ class App extends React.Component { if (draggingElement?.type === "draw") { this.actionManager.executeAction(actionFinalize); + history.resumeRecording(); return; } if (isLinearElement(draggingElement)) { diff --git a/src/tests/__snapshots__/regressionTests.test.tsx.snap b/src/tests/__snapshots__/regressionTests.test.tsx.snap index 7cbe0c81..9a46189c 100644 --- a/src/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/src/tests/__snapshots__/regressionTests.test.tsx.snap @@ -2279,6 +2279,174 @@ Object { }, ], }, + Object { + "appState": Object { + "currentItemBackgroundColor": "transparent", + "currentItemFillStyle": "hachure", + "currentItemFont": "20px Virgil", + "currentItemOpacity": 100, + "currentItemRoughness": 1, + "currentItemStrokeColor": "#000000", + "currentItemStrokeWidth": 1, + "currentItemTextAlign": "left", + "exportBackground": true, + "name": "Untitled-201933152653", + "selectedElementIds": Object { + "id7": true, + }, + "shouldAddWatermark": false, + "viewBackgroundColor": "#ffffff", + }, + "elements": Array [ + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id0", + "isDeleted": false, + "opacity": 100, + "roughness": 1, + "seed": 337897, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "rectangle", + "version": 3, + "versionNonce": 1278240551, + "width": 10, + "x": 10, + "y": 10, + }, + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id1", + "isDeleted": false, + "opacity": 100, + "roughness": 1, + "seed": 453191, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "diamond", + "version": 3, + "versionNonce": 401146281, + "width": 10, + "x": 30, + "y": 10, + }, + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id2", + "isDeleted": false, + "opacity": 100, + "roughness": 1, + "seed": 1116226695, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "ellipse", + "version": 3, + "versionNonce": 1014066025, + "width": 10, + "x": 50, + "y": 10, + }, + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id3", + "isDeleted": false, + "lastCommittedPoint": null, + "opacity": 100, + "points": Array [ + Array [ + 0, + 0, + ], + Array [ + 10, + 10, + ], + ], + "roughness": 1, + "seed": 1505387817, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "arrow", + "version": 4, + "versionNonce": 493213705, + "width": 10, + "x": 70, + "y": 10, + }, + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id4", + "isDeleted": false, + "lastCommittedPoint": null, + "opacity": 100, + "points": Array [ + Array [ + 0, + 0, + ], + Array [ + 10, + 10, + ], + ], + "roughness": 1, + "seed": 760410951, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "line", + "version": 4, + "versionNonce": 289600103, + "width": 10, + "x": 90, + "y": 10, + }, + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id7", + "isDeleted": false, + "lastCommittedPoint": null, + "opacity": 100, + "points": Array [ + Array [ + 0, + 0, + ], + Array [ + 10, + 10, + ], + ], + "roughness": 1, + "seed": 1051383431, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "draw", + "version": 4, + "versionNonce": 1279028647, + "width": 10, + "x": 30, + "y": 10, + }, + ], + }, ], } `; @@ -3019,7 +3187,59 @@ exports[`regression tests hotkey 7 selects draw tool: [end of test] history 1`] Object { "recording": false, "redoStack": Array [], - "stateHistory": Array [], + "stateHistory": Array [ + Object { + "appState": Object { + "currentItemBackgroundColor": "transparent", + "currentItemFillStyle": "hachure", + "currentItemFont": "20px Virgil", + "currentItemOpacity": 100, + "currentItemRoughness": 1, + "currentItemStrokeColor": "#000000", + "currentItemStrokeWidth": 1, + "currentItemTextAlign": "left", + "exportBackground": true, + "name": "Untitled-201933152653", + "selectedElementIds": Object { + "id0": true, + }, + "shouldAddWatermark": false, + "viewBackgroundColor": "#ffffff", + }, + "elements": Array [ + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id0", + "isDeleted": false, + "lastCommittedPoint": null, + "opacity": 100, + "points": Array [ + Array [ + 0, + 0, + ], + Array [ + 10, + 10, + ], + ], + "roughness": 1, + "seed": 337897, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "draw", + "version": 4, + "versionNonce": 449462985, + "width": 10, + "x": 10, + "y": 10, + }, + ], + }, + ], } `; @@ -3759,7 +3979,59 @@ exports[`regression tests hotkey x selects draw tool: [end of test] history 1`] Object { "recording": false, "redoStack": Array [], - "stateHistory": Array [], + "stateHistory": Array [ + Object { + "appState": Object { + "currentItemBackgroundColor": "transparent", + "currentItemFillStyle": "hachure", + "currentItemFont": "20px Virgil", + "currentItemOpacity": 100, + "currentItemRoughness": 1, + "currentItemStrokeColor": "#000000", + "currentItemStrokeWidth": 1, + "currentItemTextAlign": "left", + "exportBackground": true, + "name": "Untitled-201933152653", + "selectedElementIds": Object { + "id0": true, + }, + "shouldAddWatermark": false, + "viewBackgroundColor": "#ffffff", + }, + "elements": Array [ + Object { + "angle": 0, + "backgroundColor": "transparent", + "fillStyle": "hachure", + "height": 10, + "id": "id0", + "isDeleted": false, + "lastCommittedPoint": null, + "opacity": 100, + "points": Array [ + Array [ + 0, + 0, + ], + Array [ + 10, + 10, + ], + ], + "roughness": 1, + "seed": 337897, + "strokeColor": "#000000", + "strokeWidth": 1, + "type": "draw", + "version": 4, + "versionNonce": 449462985, + "width": 10, + "x": 10, + "y": 10, + }, + ], + }, + ], } `;