From: Scott Worley Date: Tue, 25 Jan 2022 21:31:52 +0000 (-0800) Subject: j/k movement keys X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/f1afad9b15dd2e672dc83bf6469532683f9c33ed?ds=sidebyside;hp=9e79bdbb90ffcb5929f76a4fb6860ed6396ac9de j/k movement keys --- 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 }); +}