From: Scott Worley Date: Fri, 28 Jan 2022 07:45:40 +0000 (-0800) Subject: Redo X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/0d1c27a8538b6a7c72743d5650c5272d7f88017a?ds=inline Redo --- diff --git a/vopamoi.ts b/vopamoi.ts index dc61007..284363b 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -215,15 +215,16 @@ function Log(prefix: string = "vp-") { const log = Log(); function UI() { - const undoLog: string[] = []; + const undoLog: string[][] = []; + const redoLog: string[][] = []; function perform(forward: string, reverse: string) { - undoLog.push(reverse); + undoLog.push([reverse, forward]); return log.recordAndApply(`${clock.now()} ${forward}`); } return { addTask: function (description: string): Element { const now = clock.now(); - undoLog.push(`State ${now} deleted`); + undoLog.push([`State ${now} deleted`, `State ${now} todo`]); return log.recordAndApply(`${now} Create ${description}`); }, addTag: function (createTimestamp: string, tag: string) { @@ -242,8 +243,17 @@ function UI() { return perform(`State ${createTimestamp} ${newState}`, `State ${createTimestamp} ${oldState}`); }, undo: function () { - if (undoLog.length > 0) { - return log.recordAndApply(`${clock.now()} ${undoLog.pop()}`); + const entry = undoLog.pop(); + if (entry) { + redoLog.push(entry); + return log.recordAndApply(`${clock.now()} ${entry[0]}`); + } + }, + redo: function () { + const entry = redoLog.pop(); + if (entry) { + undoLog.push(entry); + return log.recordAndApply(`${clock.now()} ${entry[1]}`); } }, }; @@ -464,6 +474,10 @@ function BrowserUI() { const ret = ui.undo(); if (ret && ret instanceof HTMLElement) ret.focus(); }, + redo: function () { + const ret = ui.redo(); + if (ret && ret instanceof HTMLElement) ret.focus(); + }, }; } const browserUI = BrowserUI(); @@ -504,6 +518,7 @@ function handleKey(event: any) { if (event.key == "X") return browserUI.setState("deleted"); if (event.key == "x") return browserUI.removeTag(); if (event.key == "u") return browserUI.undo(); + if (event.key == "r") return browserUI.redo(); if (event.key == "e") return browserUI.beginEdit(event); if (event.key == "t") return browserUI.beginTagEdit(event); if (event.key == "v") return (inputState = InputState.V);