X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/0d1c27a8538b6a7c72743d5650c5272d7f88017a..acd6b66a4b477803c65ffac202b44f5511d3f5d3:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 284363b..73fc5d9 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -287,8 +287,9 @@ function BrowserUI() { }, beginEdit: function (event: Event) { - const task = document.activeElement; + var task = document.activeElement; if (!task) return; + if (task.classList.contains("tag")) task = task.parentElement!; const input = document.createElement("input"); const desc = task.getElementsByClassName("desc")[0]; const oldDescription = desc.textContent!; @@ -378,6 +379,13 @@ function BrowserUI() { return valid_cursor; }, + jumpCursor: function (position: number) { + const first = this.firstVisibleTask(); + if (!first) return; + const dest = this.visibleTaskAtOffset(first, position - 1); + if (dest instanceof HTMLElement) dest.focus(); + }, + makeTopPriority: function (task: Element | null = null) { if (!task) task = document.activeElement; if (!task) return; @@ -482,6 +490,7 @@ function BrowserUI() { } const browserUI = BrowserUI(); +const scrollIncrement = 60; enum InputState { Root, S, @@ -489,8 +498,10 @@ enum InputState { VS, } var inputState = InputState.Root; +var inputCount: number | null = null; function handleKey(event: any) { + if (["Alt", "Control", "Meta", "Shift"].includes(event.key)) return; if (event.target.tagName === "INPUT") { if (event.target.id === "taskName") { if (event.key == "Enter") return browserUI.addTask(event); @@ -504,24 +515,37 @@ 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.ctrlKey) { + if (event.key == "e") return window.scrollBy(0, (inputCount ?? 1) * scrollIncrement); + if (event.key == "y") return window.scrollBy(0, (inputCount ?? 1) * -scrollIncrement); + } else { + 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(inputCount ?? 1); + if (event.key == "K") return browserUI.moveTask(-(inputCount ?? 1)); + if (event.key == "G") return browserUI.jumpCursor(inputCount ?? MAX_SAFE_INTEGER); + 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");