X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/b9f7e98914ca882508950ec54e27d78a11f5179e..e0c49063e71dd24fce0f57a5e9ad1287b8073341:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 0389a04..926a1f0 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -310,6 +310,11 @@ enum CommitOrAbort { Abort, } +interface TagFilter { + description: string; + include: (task: Element) => boolean; +} + function BrowserUI() { const viewColors: { [key: string]: string } = { all: "Gold", @@ -320,7 +325,7 @@ function BrowserUI() { todo: "White", waiting: "MediumOrchid", }; - var currentTagView: string | null = null; + var currentTagFilter: TagFilter | null = null; var currentViewState = "todo"; var taskFocusedBeforeJumpingToInput: HTMLElement | null = null; var lastTagNameEntered = ""; @@ -446,6 +451,7 @@ function BrowserUI() { var target = document.activeElement; if (!target) return null; if (target.classList.contains("tag")) target = target.parentElement!; + if (!target.classList.contains("task")) return null; return target as HTMLElement; }, @@ -525,7 +531,11 @@ function BrowserUI() { }, moveCursorVertically: function (offset: number): boolean { - const active = this.currentTask(); + let active = this.currentTask(); + if (!active) { + this.firstVisibleTask()?.focus(); + active = this.currentTask(); + } if (!active) return false; const dest = this.visibleTaskAtOffset(active, offset); if (dest !== active && dest instanceof HTMLElement) { @@ -556,7 +566,8 @@ function BrowserUI() { }, resetTagView: function () { - currentTagView = null; + currentTagFilter = null; + this.setTitle(); const taskList = document.getElementById("tasks")!; for (const task of Array.from(document.getElementsByClassName("task"))) { task.classList.remove("hide"); @@ -605,20 +616,14 @@ function BrowserUI() { return ui.setState(createTimestamp, newState, oldState); }, - setTagView: function (tag: string | null = null) { - if (tag === null) { - const target = this.currentTag(); - if (!target) return; - tag = target.textContent!; - } - - if (currentTagView !== null) { + setTagFilter: function (filter: TagFilter) { + if (currentTagFilter !== null) { this.resetTagView(); } const tasksWithTag = new Map(); for (const task of document.getElementsByClassName("task")) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { tasksWithTag.set(task.getElementsByClassName("desc")[0].textContent, [model.getPriority(task), task]); } } @@ -637,7 +642,7 @@ function BrowserUI() { } for (const task of Array.from(document.getElementsByClassName("task"))) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { task.classList.remove("hide"); } else { const superTask = highestPrioritySuperTask(task); @@ -649,7 +654,21 @@ function BrowserUI() { } } - currentTagView = tag; + currentTagFilter = filter; + this.setTitle(); + }, + + setTagView: function (tag: string | null = null) { + if (tag === null) { + const target = this.currentTag(); + if (!target) return; + tag = target.textContent!; + } + this.setTagFilter({description: tag, include: task => !!model.hasTag(task, tag!)}); + }, + + setTitle: function () { + document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter.description : ""); }, setView: function (state: string) { @@ -663,13 +682,14 @@ function BrowserUI() { sheet.removeRule(2); sheet.removeRule(2); currentViewState = state; + this.setTitle(); if (this.currentTask()?.getAttribute("data-state") !== state) { this.firstVisibleTask()?.focus(); } }, setUntaggedView: function () { - if (currentTagView !== null) { + if (currentTagFilter !== null) { this.resetTagView(); } for (const task of document.getElementsByClassName("task")) { @@ -782,6 +802,7 @@ function handleKey(event: any) { function browserInit() { log.replay(); + browserUI.setTitle(); browserUI.firstVisibleTask()?.focus(); document.body.addEventListener("keydown", handleKey, { capture: false }); }