From 82ce068972eda930c72808660efe321a6bb04d79 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Thu, 19 Mar 2020 14:51:05 +0100 Subject: [PATCH] fix history (#1009) * fix history * tweak withBatchedUpdates typing --- src/actions/actionCanvas.tsx | 11 +++-- src/actions/actionDeleteSelected.tsx | 3 +- src/actions/actionDuplicateSelection.ts | 1 + src/actions/actionExport.tsx | 15 +++++-- src/actions/actionFinalize.tsx | 1 + src/actions/actionHistory.tsx | 15 ++++--- src/actions/actionMenu.tsx | 2 + src/actions/actionProperties.tsx | 16 ++++---- src/actions/actionSelectAll.ts | 1 + src/actions/actionStyles.ts | 8 ++-- src/actions/actionZindex.tsx | 8 ++-- src/actions/manager.tsx | 24 +---------- src/actions/types.ts | 5 +-- src/components/App.tsx | 53 ++++++++++++++----------- src/data/index.ts | 1 + src/history.ts | 2 +- 16 files changed, 86 insertions(+), 80 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index b5e54df9..182da736 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -14,7 +14,10 @@ import { newElementWith } from "../element/mutateElement"; export const actionChangeViewBackgroundColor = register({ name: "changeViewBackgroundColor", perform: (_, appState, value) => { - return { appState: { ...appState, viewBackgroundColor: value } }; + return { + appState: { ...appState, viewBackgroundColor: value }, + commitToHistory: true, + }; }, PanelComponent: ({ appState, updateData }) => { return ( @@ -28,18 +31,17 @@ export const actionChangeViewBackgroundColor = register({ ); }, - commitToHistory: () => true, }); export const actionClearCanvas = register({ name: "clearCanvas", - commitToHistory: () => true, perform: elements => { return { elements: elements.map(element => newElementWith(element, { isDeleted: true }), ), appState: getDefaultAppState(), + commitToHistory: true, }; }, PanelComponent: ({ updateData }) => ( @@ -81,6 +83,7 @@ export const actionZoomIn = register({ ...appState, zoom: getNormalizedZoom(appState.zoom + ZOOM_STEP), }, + commitToHistory: false, }; }, PanelComponent: ({ updateData }) => ( @@ -107,6 +110,7 @@ export const actionZoomOut = register({ ...appState, zoom: getNormalizedZoom(appState.zoom - ZOOM_STEP), }, + commitToHistory: false, }; }, PanelComponent: ({ updateData }) => ( @@ -133,6 +137,7 @@ export const actionResetZoom = register({ ...appState, zoom: 1, }, + commitToHistory: false, }; }, PanelComponent: ({ updateData }) => ( diff --git a/src/actions/actionDeleteSelected.tsx b/src/actions/actionDeleteSelected.tsx index e8979274..dcf84341 100644 --- a/src/actions/actionDeleteSelected.tsx +++ b/src/actions/actionDeleteSelected.tsx @@ -20,12 +20,11 @@ export const actionDeleteSelected = register({ elementType: "selection", multiElement: null, }, + commitToHistory: isSomeElementSelected(elements, appState), }; }, contextItemLabel: "labels.delete", contextMenuOrder: 3, - commitToHistory: (appState, elements) => - isSomeElementSelected(elements, appState), keyTest: event => event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE, PanelComponent: ({ elements, appState, updateData }) => ( { - return { appState: { ...appState, name: value } }; + return { appState: { ...appState, name: value }, commitToHistory: false }; }, PanelComponent: ({ appState, updateData }) => ( { - return { appState: { ...appState, exportBackground: value } }; + return { + appState: { ...appState, exportBackground: value }, + commitToHistory: false, + }; }, PanelComponent: ({ appState, updateData }) => (