]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
Rename: currentTagView → currentTagFilter
[vopamoi] / vopamoi.ts
index 0389a04c2a25f0e00305f3f0232ae366dc86c597..c72884eb7d459d86d90536645d5c84374e4d5058 100644 (file)
@@ -320,7 +320,7 @@ function BrowserUI() {
     todo: "White",
     waiting: "MediumOrchid",
   };
-  var currentTagView: string | null = null;
+  var currentTagFilter: string | null = null;
   var currentViewState = "todo";
   var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
   var lastTagNameEntered = "";
@@ -446,6 +446,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 +526,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 +561,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");
@@ -612,7 +618,7 @@ function BrowserUI() {
         tag = target.textContent!;
       }
 
-      if (currentTagView !== null) {
+      if (currentTagFilter !== null) {
         this.resetTagView();
       }
 
@@ -649,7 +655,12 @@ function BrowserUI() {
         }
       }
 
-      currentTagView = tag;
+      currentTagFilter = tag;
+      this.setTitle();
+    },
+
+    setTitle: function () {
+      document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter : "");
     },
 
     setView: function (state: string) {
@@ -663,13 +674,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 +794,7 @@ function handleKey(event: any) {
 
 function browserInit() {
   log.replay();
+  browserUI.setTitle();
   browserUI.firstVisibleTask()?.focus();
   document.body.addEventListener("keydown", handleKey, { capture: false });
 }