From f0bd08b8c1464b1f6a7800be6634fe4237c7ffa7 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 14 Jun 2024 13:35:56 +0200 Subject: [PATCH] chore: bundle previous state in an object --- .../modes/tablemode/TableMode.svelte | 19 +++++++++---------- .../components/modes/treemode/TreeMode.svelte | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/lib/components/modes/tablemode/TableMode.svelte b/src/lib/components/modes/tablemode/TableMode.svelte index e8807969..fc75aca2 100644 --- a/src/lib/components/modes/tablemode/TableMode.svelte +++ b/src/lib/components/modes/tablemode/TableMode.svelte @@ -560,10 +560,14 @@ } const previousJson = json - const previousState = documentState - const previousSelection = selection - const previousSortedColumn = sortedColumn - const previousTextIsRepaired = textIsRepaired + const previousState: PreviousState = { + json: undefined, // not needed: we use patch to reconstruct the json + text, + documentState, + selection: removeEditModeFromSelection(selection), + sortedColumn, + textIsRepaired + } // execute the patch operations const undo: JSONPatchDocument = revertJSONPatchWithMoveOperations( @@ -599,12 +603,7 @@ history.add({ undo: { patch: undo, - json: undefined, // not needed: we use patch to reconstruct the json - text: undefined, - documentState, - selection: removeEditModeFromSelection(previousSelection), - sortedColumn: previousSortedColumn, - textIsRepaired: previousTextIsRepaired + ...previousState }, redo: { patch: operations, diff --git a/src/lib/components/modes/treemode/TreeMode.svelte b/src/lib/components/modes/treemode/TreeMode.svelte index e49435b2..25fcf51e 100644 --- a/src/lib/components/modes/treemode/TreeMode.svelte +++ b/src/lib/components/modes/treemode/TreeMode.svelte @@ -586,10 +586,14 @@ } const previousJson = json - const previousState = documentState - const previousSelection = selection - const previousText = text - const previousTextIsRepaired = textIsRepaired + const previousState = { + json: undefined, // not needed: we use patch to reconstruct the json + text, + documentState, + selection: removeEditModeFromSelection(selection), + textIsRepaired, + sortedColumn: null + } // execute the patch operations const undo: JSONPatchDocument = revertJSONPatchWithMoveOperations( @@ -620,12 +624,7 @@ history.add({ undo: { patch: undo, - json: undefined, // not needed, we use patch to reconstruct - text: previousText, - documentState: previousState, - selection: removeEditModeFromSelection(previousSelection), - sortedColumn: null, - textIsRepaired: previousTextIsRepaired + ...previousState }, redo: { patch: operations,