]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
Factor insertInPriorityOrder() out of setPriority()
[vopamoi] / vopamoi.ts
index bc399bcb0936153b0dcdf694af01f969b3fbc1b0..bdc8b0d2bf9acffb6bb34416b7fa165ea0227a26 100644 (file)
@@ -67,7 +67,7 @@ const Model = {
         return tag;
       }
     }
         return tag;
       }
     }
-    task.appendChild(tag);
+    task.insertBefore(tag, task.getElementsByClassName("desc")[0]!);
     return tag;
   },
 
     return tag;
   },
 
@@ -120,6 +120,17 @@ const Model = {
     }
   },
 
     }
   },
 
+  insertInPriorityOrder: function (task: Element, dest: Element) {
+    const priority = this.getPriority(task);
+    for (const t of dest.children) {
+      if (t !== task && this.getPriority(t) < priority) {
+        dest.insertBefore(task, t);
+        return;
+      }
+    }
+    dest.appendChild(task);
+  },
+
   removeTag: function (createTimestamp: string, tagName: string) {
     const task = this.getTask(createTimestamp);
     if (!task) return null;
   removeTag: function (createTimestamp: string, tagName: string) {
     const task = this.getTask(createTimestamp);
     if (!task) return null;
@@ -133,13 +144,7 @@ const Model = {
     const target = this.getTask(createTimestamp);
     if (!target) return null;
     target.setAttribute("data-priority", `${priority}`);
     const target = this.getTask(createTimestamp);
     if (!target) return null;
     target.setAttribute("data-priority", `${priority}`);
-    for (const task of document.getElementsByClassName("task")) {
-      if (task !== target && this.getPriority(task) < priority) {
-        task.parentElement!.insertBefore(target, task);
-        return target;
-      }
-    }
-    document.getElementById("tasks")!.appendChild(target);
+    this.insertInPriorityOrder(target, target.parentElement!);
     return target;
   },
 
     return target;
   },
 
@@ -276,6 +281,7 @@ function BrowserUI() {
     todo: "White",
     waiting: "MediumOrchid",
   };
     todo: "White",
     waiting: "MediumOrchid",
   };
+  var currentTagView: string | null = null;
   var currentViewState = "todo";
   var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
   var lastTagNameEntered = "";
   var currentViewState = "todo";
   var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
   var lastTagNameEntered = "";
@@ -291,6 +297,9 @@ function BrowserUI() {
         this.firstVisibleTask()?.focus();
       }
       input.value = "";
         this.firstVisibleTask()?.focus();
       }
       input.value = "";
+      if (currentTagView) {
+        ui.addTag(task.getAttribute("data-created")!, currentTagView);
+      }
       if (event.getModifierState("Control")) {
         this.makeBottomPriority(task);
       }
       if (event.getModifierState("Control")) {
         this.makeBottomPriority(task);
       }
@@ -464,6 +473,7 @@ function BrowserUI() {
     },
 
     resetTagView: function () {
     },
 
     resetTagView: function () {
+      currentTagView = null;
       for (const task of document.getElementsByClassName("task")) {
         task.classList.remove("hide");
       }
       for (const task of document.getElementsByClassName("task")) {
         task.classList.remove("hide");
       }
@@ -519,6 +529,7 @@ function BrowserUI() {
           task.classList.add("hide");
         }
       }
           task.classList.add("hide");
         }
       }
+      currentTagView = tag;
     },
 
     setView: function (state: string) {
     },
 
     setView: function (state: string) {