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.getElementsByClassName("tag")) {
+ if (child.textContent === tag) {
+ return child;
+ }
+ }
+ return null;
+ },
+
getPriority: function (task: Element): number {
if (task.hasAttribute("data-priority")) {
return parseFloat(task.getAttribute("data-priority")!);
function BrowserUI() {
var currentViewState = "todo";
var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
+ var lastTagNameEntered = "";
return {
addTask: function (event: KeyboardEvent) {
const input = <HTMLInputElement>document.getElementById("taskName");
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();
},
input.removeEventListener("blur", this.completeTagEdit);
task.removeChild(input);
task.focus();
- ui.addTag(task.getAttribute("data-created")!, newTagName);
+ if (resolution === CommitOrAbort.Commit && newTagName && !Model.hasTag(task, newTagName)) {
+ ui.addTag(task.getAttribute("data-created")!, newTagName);
+ lastTagNameEntered = newTagName;
+ }
},
firstVisibleTask: function () {