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

@@ -31,6 +31,7 @@ export function VersionProvider({ children }: { children: ComponentChildren }) {
useEffect(() => {
if (VersionIds.includes(targetVersion as VersionId) && version !== targetVersion) {
Analytics.setVersion(targetVersion as VersionId)
setVersion(targetVersion as VersionId)
}
}, [version, targetVersion])
@@ -46,6 +47,10 @@ export function VersionProvider({ children }: { children: ComponentChildren }) {
setVersion(newVersion)
}, [targetVersion])
useEffect(() => {
Analytics.setVersion(version)
}, [])
const value: Version = {
version,
changeVersion,

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()
}
}