]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
Change focus in BrowserUI, never in Model
[vopamoi] / vopamoi.ts
index 298e513fde6ff3df3abe46fc3080435ae9a854b8..a98a29b938bab1cf735a1d2bf9223a86b38eb6ea 100644 (file)
@@ -21,7 +21,6 @@ const Model = {
     task.setAttribute("tabindex", "0");
     task.setAttribute("data-created", timestamp);
     document.getElementById("tasks")!.appendChild(task);
-    task.focus();
     return task;
   },
 
@@ -51,12 +50,10 @@ const Model = {
     for (const task of document.getElementsByClassName("task")) {
       if (task !== target && this.getPriority(task) > priority) {
         task.parentElement!.insertBefore(target, task);
-        target instanceof HTMLElement && target.focus();
         return target;
       }
     }
     document.getElementById("tasks")!.appendChild(target);
-    target instanceof HTMLElement && target.focus();
     return target;
   },
 
@@ -140,6 +137,7 @@ const BrowserUI = {
     const input = <HTMLInputElement>document.getElementById("taskName");
     if (input.value) {
       const task = UI.addTask(input.value);
+      if (task && task instanceof HTMLElement) task.focus();
       input.value = "";
       if (event.getModifierState("Control")) {
         this.setPriority(task, null, document.getElementsByClassName("task")[0]);
@@ -212,6 +210,7 @@ const BrowserUI = {
     const newPriorityRounded = Math.round(newPriority);
     const okToRound = aPriority < newPriorityRounded && newPriorityRounded < bPriority;
     UI.setPriority(task.getAttribute("data-created")!, okToRound ? newPriorityRounded : newPriority, Model.getPriority(task));
+    task instanceof HTMLElement && task.focus();
   },
 
   setState: function (state: string) {