From f1afad9b15dd2e672dc83bf6469532683f9c33ed Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 25 Jan 2022 13:31:52 -0800 Subject: [PATCH 1/1] j/k movement keys --- index.html | 2 +- vopamoi.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 5721f96..5ed2498 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - +
diff --git a/vopamoi.ts b/vopamoi.ts index cfa1186..a0b2cfb 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -9,8 +9,30 @@ function addTask(description: string) { document.body.appendChild(createTask(description)); } +function moveCursor(offset: number) { + 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(); +} + +function handleKey(event: any) { + if (event.target.tagName !== "INPUT") { + if (event.key == "j") moveCursor(1); + if (event.key == "k") moveCursor(-1); + } +} + function browserCreateTask(form: any) { addTask(form.taskName.value); form.taskName.value = ""; return false; } + +function browserInit() { + document.body.addEventListener("keydown", handleKey, { capture: false }); +} -- 2.44.1