From fb19ac80ac51baf83c7f5d007586212e0bc0868e Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 27 Jan 2022 15:37:51 -0800 Subject: [PATCH] Disallow all-spaces task descriptions and tag-names --- vopamoi.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/vopamoi.ts b/vopamoi.ts index 633ffef..6519cbf 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -235,18 +235,17 @@ function BrowserUI() { return { addTask: function (event: KeyboardEvent) { const input = 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(); - 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); @@ -302,7 +301,7 @@ function BrowserUI() { 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; } -- 2.44.1