X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/4ccaa1d6e256ca198e0d15e5b51553edb063f3bf..cddbdce1bb49d2568668fccc788c8356012b3fe2:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index fe97410..24b8774 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -144,9 +144,20 @@ const Model = { setState: function (stateTimestamp: string, createTimestamp: string, state: string) { const task = this.getTask(createTimestamp); - if (task) { - task.setAttribute("data-state", state); + if (!task) return; + task.setAttribute("data-state", state); + var date = task.getElementsByClassName("statedate")[0]; + if (state === "todo") { + task.removeChild(date); + return; } + if (!date) { + date = document.createElement("span"); + date.classList.add("statedate"); + task.insertBefore(date, task.firstChild); + } + const d = new Date(parseInt(stateTimestamp)); + date.textContent = `${d.getFullYear()}-${`${d.getMonth() + 1}`.padStart(2, "0")}-${`${d.getDate()}`.padStart(2, "0")}`; }, }; @@ -254,7 +265,7 @@ function BrowserUI() { const input = document.getElementById("taskName"); if (input.value.match(/^ *$/)) return; const task = ui.addTask(input.value); - if (currentViewState === "todo") { + if (currentViewState === "todo" || currentViewState === "all") { task instanceof HTMLElement && task.focus(); } else if (this.returnFocusAfterInput()) { } else { @@ -262,7 +273,7 @@ function BrowserUI() { } input.value = ""; if (event.getModifierState("Control")) { - this.setPriority(task, null, document.getElementsByClassName("task")[0]); + this.makeTopPriority(task); } }, @@ -326,7 +337,8 @@ function BrowserUI() { firstVisibleTask: function () { for (const task of document.getElementsByClassName("task")) { - if (task instanceof HTMLElement && task.getAttribute("data-state") === currentViewState) { + const state = task.getAttribute("data-state"); + if (task instanceof HTMLElement && (state === currentViewState || (currentViewState === "all" && state !== "deleted"))) { return task; } } @@ -347,7 +359,8 @@ function BrowserUI() { while (true) { cursor = increment > 0 ? cursor.nextElementSibling : cursor.previousElementSibling; if (!cursor || !(cursor instanceof HTMLElement)) break; - if (cursor.getAttribute("data-state")! === currentViewState) { + const state = cursor.getAttribute("data-state")!; + if (state === currentViewState || (currentViewState === "all" && state !== "deleted")) { offset -= increment; valid_cursor = cursor; } @@ -356,6 +369,12 @@ function BrowserUI() { return valid_cursor; }, + makeTopPriority: function (task: Element | null = null) { + if (!task) task = document.activeElement; + if (!task) return; + this.setPriority(task, null, document.getElementsByClassName("task")[0]); + }, + moveCursor: function (offset: number): boolean { const active = document.activeElement; if (!active) return false; @@ -420,13 +439,19 @@ function BrowserUI() { const oldState = task.getAttribute("data-state")!; if (newState === oldState) return; const createTimestamp = task.getAttribute("data-created")!; - this.moveCursor(1) || this.moveCursor(-1); + if (currentViewState !== "all" || newState == "deleted") { + this.moveCursor(1) || this.moveCursor(-1); + } return ui.setState(createTimestamp, newState, oldState); }, setView: function (state: string, color: string) { const sheet = (document.getElementById("viewStyle") as HTMLStyleElement).sheet!; - sheet.insertRule(`.task:not([data-state=${state}]) { display: none }`); + if (state === "all") { + sheet.insertRule(`.task[data-state=deleted] { display: none }`); + } else { + sheet.insertRule(`.task:not([data-state=${state}]) { display: none }`); + } sheet.insertRule(`:root { --view-state-indicator-color: ${color}; }`); sheet.removeRule(2); sheet.removeRule(2); @@ -445,10 +470,12 @@ function BrowserUI() { const browserUI = BrowserUI(); enum InputState { - Command, - View, + Root, + S, + V, + VS, } -var inputState = InputState.Command; +var inputState = InputState.Root; function handleKey(event: any) { if (event.target.tagName === "INPUT") { @@ -463,32 +490,40 @@ function handleKey(event: any) { if (event.key == "Escape") return browserUI.completeEdit(event, CommitOrAbort.Abort); } } else { - if (inputState === InputState.Command) { + 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 browserUI.setState("someday-maybe"); + 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 == "e") return browserUI.beginEdit(event); if (event.key == "t") return browserUI.beginTagEdit(event); - if (event.key == "v") return (inputState = InputState.View); - } else if (inputState === InputState.View) { - inputState = InputState.Command; + if (event.key == "v") return (inputState = InputState.V); + } else if (inputState === InputState.S) { + inputState = InputState.Root; + if (event.key == "m") return browserUI.setState("someday-maybe"); + } else if (inputState === InputState.V) { + inputState = InputState.Root; + if (event.key == "a") return browserUI.setView("all", "Gold"); if (event.key == "c") return browserUI.setView("cancelled", "Red"); if (event.key == "d") return browserUI.setView("done", "LawnGreen"); if (event.key == "q") return browserUI.setView("todo", "White"); - if (event.key == "s") return browserUI.setView("someday-maybe", "DeepSkyBlue"); + if (event.key == "s") return (inputState = InputState.VS); if (event.key == "v") return browserUI.setView("todo", "White"); if (event.key == "w") return browserUI.setView("waiting", "MediumOrchid"); if (event.key == "x") return browserUI.setView("deleted", "Black"); + } else if (inputState === InputState.VS) { + inputState = InputState.Root; + if (event.key == "m") return browserUI.setView("someday-maybe", "DeepSkyBlue"); } } }