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) {
+ hasTag: function (task: Element, tag: string): Element | null {
for (const child of task.children) {
if (child.classList.contains("tag") && child.textContent === tag) {
- return true;
+ return child;
}
}
- return false;
+ return null;
},
getPriority: function (task: Element): number {
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();
},
task.focus();
if (!Model.hasTag(task, newTagName)) {
ui.addTag(task.getAttribute("data-created")!, newTagName);
+ lastTagNameEntered = newTagName;
}
},