X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/7b5b90b9a161fdeeb9842029a369d0484146ef4d..634868c9a2d36621da56cc6be8a863b5e90db941:/vopamoi.ts?ds=inline diff --git a/vopamoi.ts b/vopamoi.ts index 5ac82ef..d0f4fa1 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -44,6 +44,8 @@ const Model = { 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"); @@ -77,6 +79,15 @@ const Model = { 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")!); @@ -204,6 +215,7 @@ enum CommitOrAbort { function BrowserUI() { var currentViewState = "todo"; var taskFocusedBeforeJumpingToInput: HTMLElement | null = null; + var lastTagNameEntered = ""; return { addTask: function (event: KeyboardEvent) { const input = document.getElementById("taskName"); @@ -242,8 +254,10 @@ function BrowserUI() { 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(); }, @@ -270,7 +284,10 @@ function BrowserUI() { 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 () {