Fix history index tracking

This commit is contained in:
Misode
2022-05-09 03:16:15 +02:00
parent 2593172855
commit 9e12bbf558
2 changed files with 9 additions and 4 deletions

View File

@@ -168,21 +168,21 @@ export function Generator({}: Props) {
}
const undo = (e: MouseEvent) => {
e.stopPropagation()
Analytics.undoGenerator(gen.id, (model?.historyIndex ?? 1) - 1, 'menu')
Analytics.undoGenerator(gen.id, model?.historyIndex ?? 1, 'menu')
model?.undo()
}
const redo = (e: MouseEvent) => {
e.stopPropagation()
Analytics.redoGenerator(gen.id, (model?.historyIndex ?? 1) + 1, 'menu')
Analytics.redoGenerator(gen.id, model?.historyIndex ?? 1, 'menu')
model?.redo()
}
const onKeyUp = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'z') {
Analytics.undoGenerator(gen.id, (model?.historyIndex ?? 1) - 1, 'hotkey')
Analytics.undoGenerator(gen.id, model?.historyIndex ?? 1, 'hotkey')
model?.undo()
} else if (e.ctrlKey && e.key === 'y') {
Analytics.redoGenerator(gen.id, (model?.historyIndex ?? 1) + 1, 'hotkey')
Analytics.redoGenerator(gen.id, model?.historyIndex ?? 1, 'hotkey')
model?.redo()
}
}