Skip to content

Commit

Permalink
Extracts history push to own function (#5382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rein Van Imschoot authored Apr 3, 2023
1 parent b52e08b commit 42b60fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/slate-history/src/history-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface HistoryEditor extends BaseEditor {
history: History
undo: () => void
redo: () => void
writeHistory: (stack: 'undos' | 'redos', batch: any) => void
}

// eslint-disable-next-line no-redeclare
Expand Down
10 changes: 7 additions & 3 deletions packages/slate-history/src/with-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
})

history.redos.pop()
history.undos.push(batch)
e.writeHistory('undos', batch)
}
}

Expand All @@ -61,7 +61,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
})
})

history.redos.push(batch)
e.writeHistory('redos', batch)
history.undos.pop()
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
operations: [op],
selectionBefore: e.selection,
}
undos.push(batch)
e.writeHistory('undos', batch)
}

while (undos.length > 100) {
Expand All @@ -110,6 +110,10 @@ export const withHistory = <T extends Editor>(editor: T) => {
apply(op)
}

e.writeHistory = (stack: 'undos' | 'redos', batch: any) => {
e.history[stack].push(batch)
}

return e
}

Expand Down

0 comments on commit 42b60fb

Please sign in to comment.