X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/c2226333bbb69b5110aa5feaf839347321dca9ee..312acaa82bc2f7d8c1d0aa435f606d3e87c42e54:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 7777f36..76c2d29 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -355,10 +355,25 @@ function BrowserUI() { } }, + currentTag: function (): Element | null { + var target = document.activeElement; + if (!target) return null; + if (target.classList.contains("task")) { + const tags = target.getElementsByClassName("tag"); + target = tags[tags.length - 1]; + } + if (!target || !target.classList.contains("tag")) return null; + return target; + }, + firstVisibleTask: function () { for (const task of document.getElementsByClassName("task")) { const state = task.getAttribute("data-state"); - if (task instanceof HTMLElement && (state === currentViewState || (currentViewState === "all" && state !== "deleted"))) { + if ( + task instanceof HTMLElement && + (state === currentViewState || (currentViewState === "all" && state !== "deleted")) && + !task.classList.contains("hide") + ) { return task; } } @@ -381,7 +396,10 @@ function BrowserUI() { cursor = increment > 0 ? cursor.nextElementSibling : cursor.previousElementSibling; if (!cursor || !(cursor instanceof HTMLElement)) break; const state = cursor.getAttribute("data-state")!; - if (state === currentViewState || (currentViewState === "all" && state !== "deleted")) { + if ( + (state === currentViewState || (currentViewState === "all" && state !== "deleted")) && + !cursor.classList.contains("hide") + ) { offset -= increment; valid_cursor = cursor; } @@ -436,16 +454,22 @@ function BrowserUI() { }, removeTag: function () { - var target = document.activeElement; + const target = this.currentTag(); if (!target) return; - if (target.classList.contains("task")) { - const tags = target.getElementsByClassName("tag"); - target = tags[tags.length - 1]; - } - if (!target || !target.classList.contains("tag")) return; ui.removeTag(target.parentElement!.getAttribute("data-created")!, target.textContent!); }, + resetTagView: function () { + for (const task of document.getElementsByClassName("task")) { + task.classList.remove("hide"); + } + }, + + resetView: function () { + this.setView("todo"); + this.resetTagView(); + }, + returnFocusAfterInput: function (): boolean { if (taskFocusedBeforeJumpingToInput) { taskFocusedBeforeJumpingToInput.focus(); @@ -480,6 +504,19 @@ function BrowserUI() { return ui.setState(createTimestamp, newState, oldState); }, + setTagView: function () { + const target = this.currentTag(); + if (!target) return; + const tag = target.textContent!; + for (const task of document.getElementsByClassName("task")) { + if (Model.hasTag(task, tag)) { + task.classList.remove("hide"); + } else { + task.classList.add("hide"); + } + } + }, + setView: function (state: string) { const sheet = (document.getElementById("viewStyle") as HTMLStyleElement).sheet!; if (state === "all") { @@ -574,7 +611,9 @@ function handleKey(event: any) { if (event.key == "d") return browserUI.setView("done"); if (event.key == "q") return browserUI.setView("todo"); if (event.key == "s") return (inputState = InputState.VS); - if (event.key == "v") return browserUI.setView("todo"); + if (event.key == "T") return browserUI.resetTagView(); + if (event.key == "t") return browserUI.setTagView(); + if (event.key == "v") return browserUI.resetView(); if (event.key == "w") return browserUI.setView("waiting"); if (event.key == "x") return browserUI.setView("deleted"); } else if (inputState === InputState.VS) {