Skip to content

Commit

Permalink
Fix undo-redo
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 28, 2023
1 parent c8be2d3 commit 43f19d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/undo-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class UndoButton {
'button',
{
onclick: () => dispatch({ undo: true }),
disabled: state.done.length < 1,
disabled: state.done.length <= 1,
},
'⤴ Undo'
)
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const baseControls = [
// quasi - reducer function
function historyUpdateState(state, action) {
if (action.undo) {
if (state.done.length <= 1) return state
let redone = state.done.pop()
return cached({
...state,
Expand All @@ -54,6 +55,7 @@ function historyUpdateState(state, action) {
}

if (action.redo) {
if (state.redone.length < 1) return state
let picture = state.redone.pop()
return cached({
...state,
Expand Down

0 comments on commit 43f19d3

Please sign in to comment.