From: Scott Worley Date: Thu, 10 Feb 2022 00:29:10 +0000 (-0800) Subject: currentTag helper X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/5800003c2aef2d94e7225ef54c7e6eb782ac8514 currentTag helper --- diff --git a/vopamoi.ts b/vopamoi.ts index 7777f36..8cdc71f 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -355,6 +355,17 @@ function BrowserUI() { } }, + currentTag: function (): Element | null { + var target = document.activeElement; + if (!target) return null; + if (target.classList.contains("task")) { + const tags = target.getElementsByClassName("tag"); + target = tags[tags.length - 1]; + } + if (!target || !target.classList.contains("tag")) return null; + return target; + }, + firstVisibleTask: function () { for (const task of document.getElementsByClassName("task")) { const state = task.getAttribute("data-state"); @@ -436,13 +447,8 @@ function BrowserUI() { }, removeTag: function () { - var target = document.activeElement; + const target = this.currentTag(); if (!target) return; - if (target.classList.contains("task")) { - const tags = target.getElementsByClassName("tag"); - target = tags[tags.length - 1]; - } - if (!target || !target.classList.contains("tag")) return; ui.removeTag(target.parentElement!.getAttribute("data-created")!, target.textContent!); },