X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/27c6778445473dedef08331260f1db3f2bea75ef..854992ec001df4ca15d25e24dbc558353032e3b7:/vopamoi.ts?ds=sidebyside diff --git a/vopamoi.ts b/vopamoi.ts index 271354f..4280ffc 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -310,6 +310,12 @@ const BrowserUI = { }, }; +enum InputState { + Command, + View, +} +var inputState = InputState.Command; + function handleKey(event: any) { if (event.target.tagName === "INPUT") { if (event.target.id === "taskName") { @@ -318,19 +324,24 @@ function handleKey(event: any) { if (event.key == "Enter") return BrowserUI.completeEdit(event); } } else { - if (event.key == "j") return BrowserUI.moveCursor(1); - if (event.key == "k") return BrowserUI.moveCursor(-1); - if (event.key == "J") return BrowserUI.moveTask(1); - if (event.key == "K") return BrowserUI.moveTask(-1); - if (event.key == "n") return BrowserUI.focusTaskNameInput(event); - if (event.key == "s") return BrowserUI.setState("someday-maybe"); - if (event.key == "w") return BrowserUI.setState("waiting"); - if (event.key == "d") return BrowserUI.setState("done"); - if (event.key == "c") return BrowserUI.setState("cancelled"); - if (event.key == "t") return BrowserUI.setState("todo"); - if (event.key == "X") return BrowserUI.setState("deleted"); - if (event.key == "u") return BrowserUI.undo(); - if (event.key == "e") return BrowserUI.beginEdit(event); + if (inputState === InputState.Command) { + if (event.key == "j") return BrowserUI.moveCursor(1); + if (event.key == "k") return BrowserUI.moveCursor(-1); + if (event.key == "J") return BrowserUI.moveTask(1); + if (event.key == "K") return BrowserUI.moveTask(-1); + if (event.key == "n") return BrowserUI.focusTaskNameInput(event); + if (event.key == "s") return BrowserUI.setState("someday-maybe"); + if (event.key == "w") return BrowserUI.setState("waiting"); + if (event.key == "d") return BrowserUI.setState("done"); + if (event.key == "c") return BrowserUI.setState("cancelled"); + if (event.key == "t") return BrowserUI.setState("todo"); + if (event.key == "X") return BrowserUI.setState("deleted"); + if (event.key == "u") return BrowserUI.undo(); + if (event.key == "e") return BrowserUI.beginEdit(event); + if (event.key == "v") return (inputState = InputState.View); + } else if (inputState === InputState.View) { + return (inputState = InputState.Command); + } } }