From: Scott Worley Date: Wed, 26 Jan 2022 07:51:50 +0000 (-0800) Subject: Move focusTaskNameInput and moveCursor into BrowserUI X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/09657615b47a9634b20a1ab5abf2172d1575f56c?hp=799f4e8974924591b197be553e8c03947debdb33 Move focusTaskNameInput and moveCursor into BrowserUI --- diff --git a/vopamoi.ts b/vopamoi.ts index 3ff3918..56c4813 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,38 @@ const BrowserUI = { } return false; }, + destroyTask: function () { const createTimestamp = document.activeElement?.getAttribute("data-created"); return createTimestamp && 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(); } }