From 09657615b47a9634b20a1ab5abf2172d1575f56c Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 25 Jan 2022 23:51:50 -0800 Subject: [PATCH 1/1] Move focusTaskNameInput and moveCursor into BrowserUI --- vopamoi.ts | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) 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(); } } -- 2.44.1