addTag: function (createTimestamp: string, tagName: string): Element | null {
const task = this.getTask(createTimestamp);
if (!task) return null;
+ const existingTag = this.hasTag(task, tagName);
+ if (existingTag) return existingTag;
const tag = document.createElement("span");
tag.appendChild(document.createTextNode(tagName));
tag.classList.add("tag");
return target;
},
+ hasTag: function (task: Element, tag: string): Element | null {
+ for (const child of task.children) {
+ if (child.classList.contains("tag") && child.textContent === tag) {
+ return child;
+ }
+ }
+ return null;
+ },
+
getPriority: function (task: Element): number {
if (task.hasAttribute("data-priority")) {
return parseFloat(task.getAttribute("data-priority")!);
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 () {