]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
The tag-input box appearing should not move other tasks' tags around
[vopamoi] / vopamoi.ts
index 3b2f1638beb180e3e6b294cfa59b23ee2c73fe3d..d0f4fa157b3645d32e1626b2cf582e208f8b2e22 100644 (file)
@@ -215,6 +215,7 @@ enum CommitOrAbort {
 function BrowserUI() {
   var currentViewState = "todo";
   var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
+  var lastTagNameEntered = "";
   return {
     addTask: function (event: KeyboardEvent) {
       const input = <HTMLInputElement>document.getElementById("taskName");
@@ -253,8 +254,10 @@ function BrowserUI() {
       const input = document.createElement("input");
       input.classList.add("tag");
       input.addEventListener("blur", this.completeTagEdit, { once: true });
+      input.value = lastTagNameEntered;
       task.appendChild(input);
       input.focus();
+      input.select();
       event.preventDefault();
     },
 
@@ -281,8 +284,9 @@ function BrowserUI() {
       input.removeEventListener("blur", this.completeTagEdit);
       task.removeChild(input);
       task.focus();
-      if (!Model.hasTag(task, newTagName)) {
+      if (resolution === CommitOrAbort.Commit && newTagName && !Model.hasTag(task, newTagName)) {
         ui.addTag(task.getAttribute("data-created")!, newTagName);
+        lastTagNameEntered = newTagName;
       }
     },