]> git.scottworley.com Git - vopamoi/commitdiff
Change focus in BrowserUI, never in Model
authorScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 02:44:21 +0000 (18:44 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 20:21:55 +0000 (12:21 -0800)
We don't want updates coming in from network sync to move focus around.

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.setAttribute("tabindex", "0");
     task.setAttribute("data-created", timestamp);
     document.getElementById("tasks")!.appendChild(task);
-    task.focus();
     return task;
   },
 
     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);
     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);
         return target;
       }
     }
     document.getElementById("tasks")!.appendChild(target);
-    target instanceof HTMLElement && target.focus();
     return target;
   },
 
     return target;
   },
 
@@ -140,6 +137,7 @@ const BrowserUI = {
     const input = <HTMLInputElement>document.getElementById("taskName");
     if (input.value) {
       const task = UI.addTask(input.value);
     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]);
       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));
     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) {
   },
 
   setState: function (state: string) {