Skip to content

Commit

Permalink
Core Data: Fix undo approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Sep 15, 2019
1 parent dd7782a commit d195dae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
4 changes: 1 addition & 3 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ function withPersistentBlockChange( reducer ) {
// In comparing against the previous action, consider only those which
// would have qualified as one which would have been ignored or not
// have resulted in a changed state.
if ( ! isExplicitPersistentChange ) {
lastAction = action;
}
lastAction = action;

return nextState;
};
Expand Down
27 changes: 5 additions & 22 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,32 +322,15 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
return nextState;
}

let nextState;
if ( state.length === 0 ) {
// Create an initial entry so that we can undo to it.
nextState = [
{
kind: action.meta.undo.kind,
name: action.meta.undo.name,
recordId: action.meta.undo.recordId,
edits: { ...state.flattenedUndo, ...action.meta.undo.edits },
},
];
nextState.offset = 0;
return nextState;
}

// Clear potential redos, because this only supports linear history.
nextState = state.slice( 0, state.offset || undefined );
const nextState = state.slice( 0, state.offset || undefined );
nextState.offset = 0;

nextState.push( {
kind: action.kind,
name: action.name,
recordId: action.recordId,
edits: { ...action.edits, ...state.flattenedUndo },
kind: action.meta.undo.kind,
name: action.meta.undo.name,
recordId: action.meta.undo.recordId,
edits: { ...state.flattenedUndo, ...action.meta.undo.edits },
} );

return nextState;
}

Expand Down

0 comments on commit d195dae

Please sign in to comment.