]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
Disallow all-spaces task descriptions and tag-names
[vopamoi] / vopamoi.ts
index e99777c6e986c91235060b22630b74b007808efc..6519cbfc4367a1f2290a5598b07f9f001d9a87c4 100644 (file)
@@ -235,18 +235,17 @@ function BrowserUI() {
   return {
     addTask: function (event: KeyboardEvent) {
       const input = <HTMLInputElement>document.getElementById("taskName");
   return {
     addTask: function (event: KeyboardEvent) {
       const input = <HTMLInputElement>document.getElementById("taskName");
-      if (input.value) {
-        const task = ui.addTask(input.value);
-        if (currentViewState === "todo") {
-          task instanceof HTMLElement && task.focus();
-        } else if (this.returnFocusAfterInput()) {
-        } else {
-          this.firstVisibleTask()?.focus();
-        }
-        input.value = "";
-        if (event.getModifierState("Control")) {
-          this.setPriority(task, null, document.getElementsByClassName("task")[0]);
-        }
+      if (input.value.match(/^ *$/)) return;
+      const task = ui.addTask(input.value);
+      if (currentViewState === "todo") {
+        task instanceof HTMLElement && task.focus();
+      } else if (this.returnFocusAfterInput()) {
+      } else {
+        this.firstVisibleTask()?.focus();
+      }
+      input.value = "";
+      if (event.getModifierState("Control")) {
+        this.setPriority(task, null, document.getElementsByClassName("task")[0]);
       }
     },
 
       }
     },
 
@@ -288,7 +287,7 @@ function BrowserUI() {
       task.removeChild(input);
       task.removeAttribute("data-description");
       task.focus();
       task.removeChild(input);
       task.removeAttribute("data-description");
       task.focus();
-      if (newDescription === oldDescription || resolution === CommitOrAbort.Abort) {
+      if (resolution === CommitOrAbort.Abort || newDescription.match(/^ *$/) || newDescription === oldDescription) {
         desc.textContent = oldDescription;
       } else {
         ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
         desc.textContent = oldDescription;
       } else {
         ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
@@ -302,7 +301,7 @@ function BrowserUI() {
       input.removeEventListener("blur", this.completeTagEdit);
       task.removeChild(input);
       task.focus();
       input.removeEventListener("blur", this.completeTagEdit);
       task.removeChild(input);
       task.focus();
-      if (resolution === CommitOrAbort.Commit && newTagName && !Model.hasTag(task, newTagName)) {
+      if (resolution === CommitOrAbort.Commit && !newTagName.match(/^ *$/) && !Model.hasTag(task, newTagName)) {
         ui.addTag(task.getAttribute("data-created")!, newTagName);
         lastTagNameEntered = newTagName;
       }
         ui.addTag(task.getAttribute("data-created")!, newTagName);
         lastTagNameEntered = newTagName;
       }
@@ -465,7 +464,7 @@ function handleKey(event: any) {
 }
 
 function browserInit() {
 }
 
 function browserInit() {
-  document.body.addEventListener("keydown", handleKey, { capture: false });
   log.replay();
   browserUI.firstVisibleTask()?.focus();
   log.replay();
   browserUI.firstVisibleTask()?.focus();
+  document.body.addEventListener("keydown", handleKey, { capture: false });
 }
 }