X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/9e79bdbb90ffcb5929f76a4fb6860ed6396ac9de..f1afad9b15dd2e672dc83bf6469532683f9c33ed:/vopamoi.ts 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 }); +}