X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/e88c099c05a14bc0851cbab622938cdd4e8c6cc9..4101e1b1dab33f7fcdfd4a26edab2e79b66716d6:/vopamoi.ts?ds=sidebyside diff --git a/vopamoi.ts b/vopamoi.ts index 654a7a8..4e69d0f 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -14,15 +14,16 @@ function splitN(str: string, delimiter: string, limit: number = MAX_SAFE_INTEGER } const Model = { - createTask: function (description: string) { + createTask: function (timestamp: string, description: string) { const task = document.createElement("div"); task.appendChild(document.createTextNode(description)); task.setAttribute("tabindex", "0"); + task.setAttribute("data-created", timestamp); return task; }, - addTask: function (description: string) { - document.body.appendChild(this.createTask(description)).focus(); + addTask: function (timestamp: string, description: string) { + document.body.appendChild(this.createTask(timestamp, description)).focus(); }, moveCursor: function (offset: number) { @@ -43,7 +44,7 @@ const Log = (function () { apply: function (entry: string) { const [timestamp, command, data] = splitN(entry, " ", 2); if (command == "Create") { - Model.addTask(data); + Model.addTask(timestamp, data); } }, @@ -75,14 +76,16 @@ const UI = { }, }; +function focusTaskNameInput(event: any) { + document.getElementById("taskName")!.focus(); + event.preventDefault(); +} + function handleKey(event: any) { if (event.target.tagName !== "INPUT") { - if (event.key == "j") Model.moveCursor(1); - if (event.key == "k") Model.moveCursor(-1); - if (event.key == "c") { - document.getElementById("taskName")!.focus(); - event.preventDefault(); - } + if (event.key == "j") return Model.moveCursor(1); + if (event.key == "k") return Model.moveCursor(-1); + if (event.key == "c") return focusTaskNameInput(event); } }