1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-31 20:40:19 +02:00

Extracts history push to own function (#5382)

This commit is contained in:
Rein Van Imschoot
2023-04-03 20:18:17 +02:00
committed by GitHub
parent b52e08b0ea
commit 42b60fb0eb
2 changed files with 8 additions and 3 deletions

View File

@@ -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

View File

@@ -37,7 +37,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
})
history.redos.pop()
history.undos.push(batch)
e.writeHistory('undos', batch)
}
}
@@ -61,7 +61,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
})
})
history.redos.push(batch)
e.writeHistory('redos', batch)
history.undos.pop()
}
}
@@ -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) {
@@ -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
}