From 88bd89ef027fe592d38d5e99a3fbeff8109d8c0a Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 9 Feb 2022 11:48:21 -0800 Subject: [PATCH 1/1] Invert priorities Making "high" priorities low numbers was a mistake. 1. Things that come freshly to attention are much more often among the highest priority things and are very rarely lower priority that everything else being tracked. 2. Logging the completion of an already-done task, a task that was *so* high-priority that it was completed before even being tracked here, feels bad when it ends up initially marked as lowest-priority-ever unless some additional action is taken. 3. Marking a new task highest-ever-priority is fairly common and oughtn't cost two log entries. 4. All the high priority tasks ever tracked oughtn't be fighting over the smallest-representable IEEE floating point values, as they all try to get slightly closer to zero. When highest-priority is now(), these tasks get nicely spread out over the keyspace. This helps with * keeping priority values integer-rounded, which helps with * serialized log size * log parsing simplicity (clients needn't support scientific notation) * preventing underflow * making the priority-sorted 'done' views be not-completely-useless as all the tasks that have ever been high-priority get haphazardly interleaved near zero. Instead, it becomes almost chronological. This change does rather a lot of violence to current users of this tool, inverting their displayed task list order & making no provision whatsoever for gentle migration across this change of an implementation detail. This is fine, because there's still only one user of this tool: the author. Breaking changes like this will not be tolerated after deployment. --- vopamoi.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/vopamoi.ts b/vopamoi.ts index 3b0b470..57c7686 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -46,7 +46,8 @@ const Model = { task.setAttribute("tabindex", "0"); task.setAttribute("data-created", timestamp); task.setAttribute("data-state", "todo"); - document.getElementById("tasks")!.appendChild(task); + const tasks = document.getElementById("tasks")!; + tasks.insertBefore(task, tasks.firstElementChild); return task; }, @@ -133,7 +134,7 @@ const Model = { if (!target) return null; target.setAttribute("data-priority", `${priority}`); for (const task of document.getElementsByClassName("task")) { - if (task !== target && this.getPriority(task) > priority) { + if (task !== target && this.getPriority(task) < priority) { task.parentElement!.insertBefore(target, task); return target; } @@ -282,7 +283,7 @@ function BrowserUI() { } input.value = ""; if (event.getModifierState("Control")) { - this.makeTopPriority(task); + this.makeBottomPriority(task); } }, @@ -387,10 +388,17 @@ function BrowserUI() { if (dest instanceof HTMLElement) dest.focus(); }, + makeBottomPriority: function (task: Element | null = null) { + if (!task) task = document.activeElement; + if (!task) return; + this.setPriority(task, document.getElementById("tasks")!.lastElementChild, null); + }, + makeTopPriority: function (task: Element | null = null) { if (!task) task = document.activeElement; if (!task) return; - this.setPriority(task, null, document.getElementsByClassName("task")[0]); + ui.setPriority(task.getAttribute("data-created")!, clock.now(), Model.getPriority(task)); + task instanceof HTMLElement && task.focus(); }, moveCursor: function (offset: number): boolean { @@ -439,14 +447,14 @@ function BrowserUI() { // Change task's priority to be between other tasks a and b. setPriority: function (task: Element, a: Element | null, b: Element | null) { - const aPriority = a === null ? 0 : Model.getPriority(a); - const bPriority = b === null ? clock.now() : Model.getPriority(b); - console.assert(aPriority < bPriority, aPriority, "<", bPriority); - const span = bPriority - aPriority; - const newPriority = aPriority + 0.1 * span + 0.8 * span * Math.random(); - console.assert(aPriority < newPriority && newPriority < bPriority, aPriority, "<", newPriority, "<", bPriority); + const aPriority = a === null ? clock.now() : Model.getPriority(a); + const bPriority = b === null ? 0 : Model.getPriority(b); + console.assert(aPriority > bPriority, aPriority, ">", bPriority); + const span = aPriority - bPriority; + const newPriority = bPriority + 0.1 * span + 0.8 * span * Math.random(); + console.assert(aPriority > newPriority && newPriority > bPriority, aPriority, ">", newPriority, ">", bPriority); const newPriorityRounded = Math.round(newPriority); - const okToRound = aPriority < newPriorityRounded && newPriorityRounded < bPriority; + const okToRound = aPriority > newPriorityRounded && newPriorityRounded > bPriority; ui.setPriority(task.getAttribute("data-created")!, okToRound ? newPriorityRounded : newPriority, Model.getPriority(task)); task instanceof HTMLElement && task.focus(); }, -- 2.44.1