From: Scott Worley Date: Sat, 29 Jan 2022 20:23:21 +0000 (-0800) Subject: vi-style count-prefix for cursor movement X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/36fa06f4ee3f58be1677a326c38731553f0f3995?hp=0d1c27a8538b6a7c72743d5650c5272d7f88017a vi-style count-prefix for cursor movement --- diff --git a/vopamoi.ts b/vopamoi.ts index 284363b..3ccc562 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -489,6 +489,7 @@ enum InputState { VS, } var inputState = InputState.Root; +var inputCount: number | null = null; function handleKey(event: any) { if (event.target.tagName === "INPUT") { @@ -504,24 +505,31 @@ function handleKey(event: any) { } } else { if (inputState === InputState.Root) { - 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 == "T") return browserUI.makeTopPriority(); - if (event.key == "n") return browserUI.focusTaskNameInput(event); - if (event.key == "c") return browserUI.setState("cancelled"); - if (event.key == "d") return browserUI.setState("done"); - if (event.key == "q") return browserUI.setState("todo"); - if (event.key == "s") return (inputState = InputState.S); - if (event.key == "w") return browserUI.setState("waiting"); - if (event.key == "X") return browserUI.setState("deleted"); - if (event.key == "x") return browserUI.removeTag(); - if (event.key == "u") return browserUI.undo(); - if (event.key == "r") return browserUI.redo(); - if (event.key == "e") return browserUI.beginEdit(event); - if (event.key == "t") return browserUI.beginTagEdit(event); - if (event.key == "v") return (inputState = InputState.V); + if ("0" <= event.key && event.key <= "9") { + return (inputCount = (inputCount ?? 0) * 10 + parseInt(event.key)); + } + try { + if (event.key == "j") return browserUI.moveCursor(inputCount ?? 1); + if (event.key == "k") return browserUI.moveCursor(-(inputCount ?? 1)); + if (event.key == "J") return browserUI.moveTask(1); + if (event.key == "K") return browserUI.moveTask(-1); + if (event.key == "T") return browserUI.makeTopPriority(); + if (event.key == "n") return browserUI.focusTaskNameInput(event); + if (event.key == "c") return browserUI.setState("cancelled"); + if (event.key == "d") return browserUI.setState("done"); + if (event.key == "q") return browserUI.setState("todo"); + if (event.key == "s") return (inputState = InputState.S); + if (event.key == "w") return browserUI.setState("waiting"); + if (event.key == "X") return browserUI.setState("deleted"); + if (event.key == "x") return browserUI.removeTag(); + if (event.key == "u") return browserUI.undo(); + if (event.key == "r") return browserUI.redo(); + if (event.key == "e") return browserUI.beginEdit(event); + if (event.key == "t") return browserUI.beginTagEdit(event); + if (event.key == "v") return (inputState = InputState.V); + } finally { + inputCount = null; + } } else if (inputState === InputState.S) { inputState = InputState.Root; if (event.key == "m") return browserUI.setState("someday-maybe");