Skip to content

Commit

Permalink
chore: bundle previous state in an object
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 14, 2024
1 parent 7c8f2ed commit f0bd08b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
19 changes: 9 additions & 10 deletions src/lib/components/modes/tablemode/TableMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 9 additions & 10 deletions src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f0bd08b

Please sign in to comment.