X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/799f4e8974924591b197be553e8c03947debdb33..615358984666136f37c15c87b78ab96b541d60bf:/vopamoi.ts?ds=inline diff --git a/vopamoi.ts b/vopamoi.ts index 3ff3918..151c5e0 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -39,21 +39,6 @@ const Model = { const task = this.getTask(createTimestamp); task!.parentElement!.removeChild(task!); }, - - moveCursor: function (offset: number): boolean { - var active = document.activeElement; - if (offset === 1 && active) { - active = active.nextElementSibling; - } - if (offset === -1 && active) { - active = active.previousElementSibling; - } - if (active && active instanceof HTMLElement) { - active.focus(); - return true; - } - return false; - }, }; const Log = (function () { @@ -108,22 +93,39 @@ const BrowserUI = { } return false; }, + destroyTask: function () { const createTimestamp = document.activeElement?.getAttribute("data-created"); - return createTimestamp && UI.destroyTask(createTimestamp); + this.moveCursor(1) || this.moveCursor(-1); + return UI.destroyTask(createTimestamp!); }, -}; -function focusTaskNameInput(event: any) { - document.getElementById("taskName")!.focus(); - event.preventDefault(); -} + focusTaskNameInput: function (event: any) { + document.getElementById("taskName")!.focus(); + event.preventDefault(); + }, + + moveCursor: function (offset: number): boolean { + var active = document.activeElement; + if (offset === 1 && active) { + active = active.nextElementSibling; + } + if (offset === -1 && active) { + active = active.previousElementSibling; + } + if (active && active instanceof HTMLElement) { + active.focus(); + return true; + } + return false; + }, +}; function handleKey(event: any) { if (event.target.tagName !== "INPUT") { - if (event.key == "j") return Model.moveCursor(1); - if (event.key == "k") return Model.moveCursor(-1); - if (event.key == "c") return focusTaskNameInput(event); + if (event.key == "j") return BrowserUI.moveCursor(1); + if (event.key == "k") return BrowserUI.moveCursor(-1); + if (event.key == "c") return BrowserUI.focusTaskNameInput(event); if (event.key == "X") return BrowserUI.destroyTask(); } }