From: Scott Worley Date: Thu, 27 Jan 2022 19:59:03 +0000 (-0800) Subject: Don't attempt to create duplicate tags X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/e1eb33ad260e5da0ec6859baa2368d8a08538e11?ds=inline;hp=7b5b90b9a161fdeeb9842029a369d0484146ef4d Don't attempt to create duplicate tags --- diff --git a/vopamoi.ts b/vopamoi.ts index 5ac82ef..7c51935 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -77,6 +77,15 @@ const Model = { return target; }, + hasTag: function (task: Element, tag: string) { + for (const child of task.children) { + if (child.classList.contains("tag") && child.textContent === tag) { + return true; + } + } + return false; + }, + getPriority: function (task: Element): number { if (task.hasAttribute("data-priority")) { return parseFloat(task.getAttribute("data-priority")!); @@ -270,7 +279,9 @@ function BrowserUI() { input.removeEventListener("blur", this.completeTagEdit); task.removeChild(input); task.focus(); - ui.addTag(task.getAttribute("data-created")!, newTagName); + if (!Model.hasTag(task, newTagName)) { + ui.addTag(task.getAttribute("data-created")!, newTagName); + } }, firstVisibleTask: function () {