From e94e9f27c762273111ae0526d6ca24cee0c02592 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 26 Jan 2022 22:53:54 -0800 Subject: [PATCH] Commands are in command mode --- vopamoi.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/vopamoi.ts b/vopamoi.ts index 271354f..80e8ff9 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -310,6 +310,11 @@ const BrowserUI = { }, }; +enum InputState { + Command, +} +var inputState = InputState.Command; + function handleKey(event: any) { if (event.target.tagName === "INPUT") { if (event.target.id === "taskName") { @@ -318,19 +323,21 @@ 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); + } } } -- 2.44.1