X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/312acaa82bc2f7d8c1d0aa435f606d3e87c42e54..8e0dd97e0d4b07448bb1bde4f109e5192df1aa77:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 76c2d29..33e37a3 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -67,7 +67,7 @@ const Model = { return tag; } } - task.appendChild(tag); + task.insertBefore(tag, task.getElementsByClassName("desc")[0]!); return tag; }, @@ -76,7 +76,7 @@ const Model = { if (!target) return null; if (target.hasAttribute("data-description")) { // Oh no: An edit has arrived from a replica while a local edit is in progress. - const input = target.firstChild as HTMLInputElement; + const input = target.getElementsByTagName("input")[0]!; if ( input.value === target.getAttribute("data-description") && input.selectionStart === input.value.length && @@ -297,9 +297,8 @@ function BrowserUI() { }, beginEdit: function (event: Event) { - var task = document.activeElement; + const task = this.currentTask(); if (!task) return; - if (task.classList.contains("tag")) task = task.parentElement!; const input = document.createElement("input"); const desc = task.getElementsByClassName("desc")[0]; const oldDescription = desc.textContent!; @@ -313,7 +312,7 @@ function BrowserUI() { }, beginTagEdit: function (event: Event) { - const task = document.activeElement; + const task = this.currentTask(); if (!task) return; const input = document.createElement("input"); input.classList.add("tag"); @@ -366,6 +365,13 @@ function BrowserUI() { return target; }, + currentTask: function (): HTMLElement | null { + var target = document.activeElement; + if (!target) return null; + if (target.classList.contains("tag")) target = target.parentElement!; + return target as HTMLElement; + }, + firstVisibleTask: function () { for (const task of document.getElementsByClassName("task")) { const state = task.getAttribute("data-state"); @@ -380,9 +386,7 @@ function BrowserUI() { }, focusTaskNameInput: function (event: Event) { - if (document.activeElement instanceof HTMLElement) { - taskFocusedBeforeJumpingToInput = document.activeElement; - } + taskFocusedBeforeJumpingToInput = this.currentTask(); document.getElementById("taskName")!.focus(); window.scroll(0, 0); event.preventDefault(); @@ -416,20 +420,20 @@ function BrowserUI() { }, makeBottomPriority: function (task: Element | null = null) { - if (!task) task = document.activeElement; + if (!task) task = this.currentTask(); if (!task) return; this.setPriority(task, document.getElementById("tasks")!.lastElementChild, null); }, makeTopPriority: function (task: Element | null = null) { - if (!task) task = document.activeElement; + if (!task) task = this.currentTask(); if (!task) return; ui.setPriority(task.getAttribute("data-created")!, clock.now(), Model.getPriority(task)); task instanceof HTMLElement && task.focus(); }, moveCursor: function (offset: number): boolean { - const active = document.activeElement; + const active = this.currentTask(); if (!active) return false; const dest = this.visibleTaskAtOffset(active, offset); if (dest !== active && dest instanceof HTMLElement) { @@ -440,7 +444,7 @@ function BrowserUI() { }, moveTask: function (offset: number) { - const active = document.activeElement; + const active = this.currentTask(); if (!active) return; const dest = this.visibleTaskAtOffset(active, offset); if (dest === active) return; // Already extremal @@ -493,7 +497,7 @@ function BrowserUI() { }, setState: function (newState: string) { - const task = document.activeElement; + const task = this.currentTask(); if (!task) return; const oldState = task.getAttribute("data-state")!; if (newState === oldState) return; @@ -528,11 +532,21 @@ function BrowserUI() { sheet.removeRule(2); sheet.removeRule(2); currentViewState = state; - if (document.activeElement?.getAttribute("data-state") !== state) { + if (this.currentTask()?.getAttribute("data-state") !== state) { this.firstVisibleTask()?.focus(); } }, + setUntaggedView: function () { + for (const task of document.getElementsByClassName("task")) { + if (task.getElementsByClassName("tag").length === 0) { + task.classList.remove("hide"); + } else { + task.classList.add("hide"); + } + } + }, + undo: function () { const ret = ui.undo(); if (ret && ret instanceof HTMLElement) ret.focus(); @@ -609,10 +623,12 @@ function handleKey(event: any) { if (event.key == "a") return browserUI.setView("all"); if (event.key == "c") return browserUI.setView("cancelled"); if (event.key == "d") return browserUI.setView("done"); + if (event.key == "i") return browserUI.setUntaggedView(); if (event.key == "q") return browserUI.setView("todo"); if (event.key == "s") return (inputState = InputState.VS); if (event.key == "T") return browserUI.resetTagView(); if (event.key == "t") return browserUI.setTagView(); + if (event.key == "u") return browserUI.setUntaggedView(); if (event.key == "v") return browserUI.resetView(); if (event.key == "w") return browserUI.setView("waiting"); if (event.key == "x") return browserUI.setView("deleted");