import { commandIds } from "@commands/ids"; import type { Dispatch } from "@commands/dispatcher"; import type { KeybindEvent } from "./keyboard"; export type HistoryActions = { undo(): void; redo(): void }; export function handleHistoryKey(options: { event: KeybindEvent; dispatch?: Dispatch; actions?: HistoryActions }): boolean { if (options.event.altKey) return false; const modifier = options.event.metaKey || options.event.ctrlKey; if (!modifier || options.event.key.toLowerCase() !== "z") return false; if (options.actions) { if (options.event.shiftKey) options.actions.redo(); else options.actions.undo(); } else if (options.dispatch) { options.dispatch(options.event.shiftKey ? commandIds.historyRedo : commandIds.historyUndo, undefined); } else { return false; } return true; }