1 // Typescript doesn't know about MAX_SAFE_INTEGER?? This was supposed to be
2 // fixed in typescript 2.0.1 in 2016, but is not working for me in typescript
3 // 4.2.4 in 2022. :( https://github.com/microsoft/TypeScript/issues/9937
4 //const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
5 const MAX_SAFE_INTEGER = 9007199254740991;
7 // A sane split that splits N *times*, leaving the last chunk unsplit.
8 function splitN(str: string, delimiter: string, limit: number = MAX_SAFE_INTEGER): string[] {
12 const at = str.indexOf(delimiter);
13 return at === -1 ? [str] : [str.substring(0, at)].concat(splitN(str.substring(at + delimiter.length), delimiter, limit - 1));
16 // A clock that never goes backwards; monotonic.
18 var previousNow = Date.now();
20 now: function (): number {
21 const now = Date.now();
22 if (now > previousNow) {
30 const clock = Clock();
32 // Returns a promise for a hue based on a hash of the string
33 function hashHue(str: string) {
34 // Using crypto for this is overkill
35 return crypto.subtle.digest("SHA-256", new TextEncoder().encode(str)).then((buf) => (new Uint16Array(buf)[0] * 360) / 2 ** 16);
40 addTask: function (timestamp: string, description: string): Element {
41 const task = document.createElement("div");
42 const desc = document.createElement("span");
43 desc.textContent = description;
44 desc.classList.add("desc");
45 task.appendChild(desc);
46 task.classList.add("task");
47 task.setAttribute("tabindex", "0");
48 task.setAttribute("id", timestamp);
49 task.setAttribute("data-state", "todo");
50 const tasks = document.getElementById("tasks")!;
51 tasks.insertBefore(task, tasks.firstElementChild);
55 addTag: function (createTimestamp: string, tagName: string): Element | null {
56 const task = this.getTask(createTimestamp);
57 if (!task) return null;
58 const existingTag = this.hasTag(task, tagName);
59 if (existingTag) return existingTag;
60 const tag = document.createElement("span");
61 tag.appendChild(document.createTextNode(tagName));
62 tag.classList.add("tag");
63 tag.setAttribute("tabindex", "0");
64 hashHue(tagName).then((hue) => (tag.style.backgroundColor = `hsl(${hue},90%,45%)`));
65 for (const child of task.getElementsByClassName("tag")) {
66 if (tagName > child.textContent!) {
67 task.insertBefore(tag, child);
71 task.insertBefore(tag, task.getElementsByClassName("desc")[0]!);
75 edit: function (createTimestamp: string, newDescription: string): Element | null {
76 const target = this.getTask(createTimestamp);
77 if (!target) return null;
78 if (target.hasAttribute("data-description")) {
79 // Oh no: An edit has arrived from a replica while a local edit is in progress.
80 const input = target.getElementsByTagName("input")[0]!;
82 input.value === target.getAttribute("data-description") &&
83 input.selectionStart === input.value.length &&
84 input.selectionEnd === input.value.length
86 // No local changes have actually been made yet. Change the contents of the edit box!
87 input.value = newDescription;
90 // Prefer not to interrupt the local user's edit.
91 // The remote edit is mostly lost; this mostly becomes last-write-wins.
92 target.setAttribute("data-description", newDescription);
95 target.getElementsByClassName("desc")[0].textContent = newDescription;
100 editContent: function (createTimestamp: string, newContent: string): Element | null {
101 const target = this.getTask(createTimestamp);
102 if (!target) return null;
103 if (target.hasAttribute("data-content")) {
104 // Oh no: An edit has arrived from a replica while a local edit is in progress.
105 const input = target.getElementsByTagName("textarea")[0]!;
107 input.value === target.getAttribute("data-content") &&
108 input.selectionStart === input.value.length &&
109 input.selectionEnd === input.value.length
111 // No local changes have actually been made yet. Change the contents of the edit box!
112 input.value = newContent;
115 // Prefer not to interrupt the local user's edit.
116 // The remote edit is mostly lost; this mostly becomes last-write-wins.
117 target.setAttribute("data-content", newContent);
120 var content = target.getElementsByClassName("content")[0];
122 content = document.createElement("div");
123 content.classList.add("content");
124 target.appendChild(content);
126 content.textContent = newContent;
131 hasTag: function (task: Element, tag: string): Element | null {
132 for (const child of task.getElementsByClassName("tag")) {
133 if (child.textContent === tag) {
140 getPriority: function (task: Element): number {
141 if (task.hasAttribute("data-priority")) {
142 return parseFloat(task.getAttribute("data-priority")!);
144 return parseFloat(task.getAttribute("id")!);
147 getTask: function (createTimestamp: string) {
148 return document.getElementById(createTimestamp);
151 insertInPriorityOrder: function (task: Element, dest: Element) {
152 const priority = this.getPriority(task);
153 for (const t of dest.children) {
154 if (t !== task && this.getPriority(t) < priority) {
155 dest.insertBefore(task, t);
159 dest.appendChild(task);
162 removeTag: function (createTimestamp: string, tagName: string) {
163 const task = this.getTask(createTimestamp);
164 if (!task) return null;
165 const tag = this.hasTag(task, tagName);
167 task.removeChild(tag);
168 if (task instanceof HTMLElement) task.focus();
171 setPriority: function (createTimestamp: string, priority: number): Element | null {
172 const target = this.getTask(createTimestamp);
173 if (!target) return null;
174 target.setAttribute("data-priority", `${priority}`);
175 this.insertInPriorityOrder(target, target.parentElement!);
179 setState: function (stateTimestamp: string, createTimestamp: string, state: string) {
180 const task = this.getTask(createTimestamp);
182 task.setAttribute("data-state", state);
183 var date = task.getElementsByClassName("statedate")[0];
184 if (state === "todo") {
185 task.removeChild(date);
189 date = document.createElement("span");
190 date.classList.add("statedate");
191 task.insertBefore(date, task.firstChild);
193 const d = new Date(parseInt(stateTimestamp));
194 date.textContent = `${d.getFullYear()}-${`${d.getMonth() + 1}`.padStart(2, "0")}-${`${d.getDate()}`.padStart(2, "0")}`;
198 const model = Model();
200 function Log(prefix: string = "vp-") {
201 var next_log_index = 0;
203 apply: function (entry: string) {
204 const [timestamp, command, data] = splitN(entry, " ", 2);
205 if (command == "Create") {
206 return model.addTask(timestamp, data);
208 if (command == "Edit") {
209 const [createTimestamp, description] = splitN(data, " ", 1);
210 return model.edit(createTimestamp, description);
212 if (command == "EditContent") {
213 const [createTimestamp, content] = splitN(data, " ", 1);
214 return model.editContent(createTimestamp, content);
216 if (command == "Priority") {
217 const [createTimestamp, newPriority] = splitN(data, " ", 1);
218 return model.setPriority(createTimestamp, parseFloat(newPriority));
220 if (command == "State") {
221 const [createTimestamp, state] = splitN(data, " ", 1);
222 return model.setState(timestamp, createTimestamp, state);
224 if (command == "Tag") {
225 const [createTimestamp, tag] = splitN(data, " ", 1);
226 return model.addTag(createTimestamp, tag);
228 if (command == "Untag") {
229 const [createTimestamp, tag] = splitN(data, " ", 1);
230 return model.removeTag(createTimestamp, tag);
234 record: function (entry: string) {
235 window.localStorage.setItem(`${prefix}${next_log_index++}`, entry);
238 recordAndApply: function (entry: string) {
240 return this.apply(entry);
243 replay: function () {
244 document.getElementById("tasks")!.style.display = "none";
246 const entry = window.localStorage.getItem(`${prefix}${next_log_index}`);
247 if (entry === null) {
253 document.getElementById("tasks")!.style.display = "";
260 const undoLog: string[][] = [];
261 const redoLog: string[][] = [];
262 function perform(forward: string, reverse: string) {
263 undoLog.push([reverse, forward]);
264 return log.recordAndApply(`${clock.now()} ${forward}`);
267 addTask: function (description: string): Element {
268 const now = clock.now();
269 undoLog.push([`State ${now} deleted`, `State ${now} todo`]);
270 return <Element>log.recordAndApply(`${now} Create ${description}`);
272 addTag: function (createTimestamp: string, tag: string) {
273 return perform(`Tag ${createTimestamp} ${tag}`, `Untag ${createTimestamp} ${tag}`);
275 edit: function (createTimestamp: string, newDescription: string, oldDescription: string) {
276 return perform(`Edit ${createTimestamp} ${newDescription}`, `Edit ${createTimestamp} ${oldDescription}`);
278 editContent: function (createTimestamp: string, newContent: string, oldContent: string) {
279 return perform(`EditContent ${createTimestamp} ${newContent}`, `EditContent ${createTimestamp} ${oldContent}`);
281 removeTag: function (createTimestamp: string, tag: string) {
282 return perform(`Untag ${createTimestamp} ${tag}`, `Tag ${createTimestamp} ${tag}`);
284 setPriority: function (createTimestamp: string, newPriority: number, oldPriority: number) {
285 return perform(`Priority ${createTimestamp} ${newPriority}`, `Priority ${createTimestamp} ${oldPriority}`);
287 setState: function (createTimestamp: string, newState: string, oldState: string) {
288 return perform(`State ${createTimestamp} ${newState}`, `State ${createTimestamp} ${oldState}`);
291 const entry = undoLog.pop();
294 return log.recordAndApply(`${clock.now()} ${entry[0]}`);
298 const entry = redoLog.pop();
301 return log.recordAndApply(`${clock.now()} ${entry[1]}`);
313 interface TagFilter {
315 include: (task: Element) => boolean;
318 function BrowserUI() {
319 const viewColors: { [key: string]: string } = {
324 "someday-maybe": "DeepSkyBlue",
325 todo: "rgb(0 0 0 / 0)",
326 waiting: "MediumOrchid",
328 var currentTagFilter: TagFilter | null = null;
329 var currentViewState = "todo";
330 var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
331 var lastTagNameEntered = "";
333 addTask: function (event: KeyboardEvent) {
334 const input = <HTMLInputElement>document.getElementById("taskName");
335 if (input.value.match(/^ *$/)) return;
336 const task = ui.addTask(input.value);
337 if (currentViewState === "todo" || currentViewState === "all") {
338 task instanceof HTMLElement && task.focus();
339 } else if (this.returnFocusAfterInput()) {
341 this.firstVisibleTask()?.focus();
344 if (event.getModifierState("Control")) {
345 this.makeBottomPriority(task);
349 beginEdit: function (event: Event) {
350 const task = this.currentTask();
352 const input = document.createElement("input");
353 const desc = task.getElementsByClassName("desc")[0];
354 const oldDescription = desc.textContent!;
355 task.setAttribute("data-description", oldDescription);
356 input.value = oldDescription;
357 input.addEventListener("blur", this.completeEdit, { once: true });
358 desc.textContent = "";
359 task.insertBefore(input, task.firstChild);
361 event.preventDefault();
364 beginEditContent: function (event: Event) {
365 const task = this.currentTask();
367 const input = document.createElement("textarea");
368 const content = task.getElementsByClassName("content")[0];
369 const oldContent = content?.textContent ?? "";
370 task.setAttribute("data-content", oldContent);
371 input.value = oldContent;
372 input.addEventListener("blur", this.completeContentEdit, { once: true });
373 if (content) content.textContent = "";
374 task.appendChild(input);
376 event.preventDefault();
379 beginTagEdit: function (event: Event) {
380 const task = this.currentTask();
382 const input = document.createElement("input");
383 input.classList.add("tag");
384 input.addEventListener("blur", this.completeTagEdit, { once: true });
385 input.value = lastTagNameEntered;
386 task.appendChild(input);
389 event.preventDefault();
392 completeEdit: function (event: Event, resolution: CommitOrAbort = CommitOrAbort.Commit) {
393 const input = event.target as HTMLInputElement;
394 const task = input.parentElement!;
395 const desc = task.getElementsByClassName("desc")[0];
396 const oldDescription = task.getAttribute("data-description")!;
397 const newDescription = input.value;
398 input.removeEventListener("blur", this.completeEdit);
399 task.removeChild(input);
400 task.removeAttribute("data-description");
402 if (resolution === CommitOrAbort.Abort || newDescription.match(/^ *$/) || newDescription === oldDescription) {
403 desc.textContent = oldDescription;
405 ui.edit(task.getAttribute("id")!, newDescription, oldDescription);
409 completeContentEdit: function (event: Event, resolution: CommitOrAbort = CommitOrAbort.Commit) {
410 const input = event.target as HTMLInputElement;
411 const task = input.parentElement!;
412 const content = task.getElementsByClassName("content")[0];
413 const oldContent = task.getAttribute("data-content")!;
414 const newContent = input.value;
415 input.removeEventListener("blur", this.completeContentEdit);
416 task.removeChild(input);
417 task.removeAttribute("data-content");
419 if (resolution === CommitOrAbort.Abort || newContent === oldContent) {
420 if (content) content.textContent = oldContent;
422 ui.editContent(task.getAttribute("id")!, newContent, oldContent);
426 completeTagEdit: function (event: Event, resolution: CommitOrAbort = CommitOrAbort.Commit) {
427 const input = event.target as HTMLInputElement;
428 const task = input.parentElement!;
429 const newTagName = input.value;
430 input.removeEventListener("blur", this.completeTagEdit);
431 task.removeChild(input);
433 if (resolution === CommitOrAbort.Commit && !newTagName.match(/^ *$/) && !model.hasTag(task, newTagName)) {
434 ui.addTag(task.getAttribute("id")!, newTagName);
435 lastTagNameEntered = newTagName;
439 currentTag: function (): Element | null {
440 var target = document.activeElement;
441 if (!target) return null;
442 if (target.classList.contains("task")) {
443 const tags = target.getElementsByClassName("tag");
444 target = tags[tags.length - 1];
446 if (!target || !target.classList.contains("tag")) return null;
450 currentTask: function (): HTMLElement | null {
451 var target = document.activeElement;
452 if (!target) return null;
453 if (target.classList.contains("tag")) target = target.parentElement!;
454 if (!target.classList.contains("task")) return null;
455 return target as HTMLElement;
458 firstVisibleTask: function (root: Element | null = null) {
459 if (root === null) root = document.body;
460 for (const task of root.getElementsByClassName("task")) {
461 const state = task.getAttribute("data-state");
463 task instanceof HTMLElement &&
464 (state === currentViewState || (currentViewState === "all" && state !== "deleted")) &&
465 !task.classList.contains("hide")
472 focusTaskNameInput: function (event: Event) {
473 taskFocusedBeforeJumpingToInput = this.currentTask();
474 document.getElementById("taskName")!.focus();
476 event.preventDefault();
479 visibleTaskAtOffset(task: Element, offset: number): Element {
480 var cursor: Element | null = task;
481 var valid_cursor = cursor;
482 const increment = offset / Math.abs(offset);
484 cursor = increment > 0 ? cursor.nextElementSibling : cursor.previousElementSibling;
485 if (!cursor || !(cursor instanceof HTMLElement)) break;
486 const state = cursor.getAttribute("data-state")!;
488 (state === currentViewState || (currentViewState === "all" && state !== "deleted")) &&
489 !cursor.classList.contains("hide")
492 valid_cursor = cursor;
494 if (Math.abs(offset) < 0.5) break;
499 jumpCursor: function (position: number) {
500 const first = this.firstVisibleTask();
502 const dest = this.visibleTaskAtOffset(first, position - 1);
503 if (dest instanceof HTMLElement) dest.focus();
506 makeBottomPriority: function (task: Element | null = null) {
507 if (!task) task = this.currentTask();
509 this.setPriority(task, document.getElementById("tasks")!.lastElementChild, null);
512 makeTopPriority: function (task: Element | null = null) {
513 if (!task) task = this.currentTask();
515 ui.setPriority(task.getAttribute("id")!, clock.now(), model.getPriority(task));
516 task instanceof HTMLElement && task.focus();
519 moveCursorLeft: function () {
520 const active = this.currentTask();
521 if (!active) return false;
522 if (active.parentElement!.classList.contains("task")) {
523 active.parentElement!.focus();
527 moveCursorRight: function () {
528 const active = this.currentTask();
529 if (!active) return false;
530 (this.firstVisibleTask(active) as HTMLElement | null)?.focus();
533 moveCursorVertically: function (offset: number): boolean {
534 let active = this.currentTask();
536 this.firstVisibleTask()?.focus();
537 active = this.currentTask();
539 if (!active) return false;
540 const dest = this.visibleTaskAtOffset(active, offset);
541 if (dest !== active && dest instanceof HTMLElement) {
548 moveTask: function (offset: number) {
549 const active = this.currentTask();
551 const dest = this.visibleTaskAtOffset(active, offset);
552 if (dest === active) return; // Already extremal
553 var onePastDest: Element | null = this.visibleTaskAtOffset(dest, offset / Math.abs(offset));
554 if (onePastDest == dest) onePastDest = null; // Will become extremal
556 this.setPriority(active, dest, onePastDest);
558 this.setPriority(active, onePastDest, dest);
562 removeTag: function () {
563 const target = this.currentTag();
565 ui.removeTag(target.parentElement!.getAttribute("id")!, target.textContent!);
568 resetTagView: function () {
569 currentTagFilter = null;
571 const taskList = document.getElementById("tasks")!;
572 for (const task of Array.from(document.getElementsByClassName("task"))) {
573 task.classList.remove("hide");
574 if (task.parentElement !== taskList) {
575 model.insertInPriorityOrder(task, taskList);
580 resetView: function () {
581 this.setView("todo");
585 returnFocusAfterInput: function (): boolean {
586 if (taskFocusedBeforeJumpingToInput) {
587 taskFocusedBeforeJumpingToInput.focus();
593 // Change task's priority to be between other tasks a and b.
594 setPriority: function (task: Element, a: Element | null, b: Element | null) {
595 const aPriority = a === null ? clock.now() : model.getPriority(a);
596 const bPriority = b === null ? 0 : model.getPriority(b);
597 console.assert(aPriority > bPriority, aPriority, ">", bPriority);
598 const span = aPriority - bPriority;
599 const newPriority = bPriority + 0.1 * span + 0.8 * span * Math.random();
600 console.assert(aPriority > newPriority && newPriority > bPriority, aPriority, ">", newPriority, ">", bPriority);
601 const newPriorityRounded = Math.round(newPriority);
602 const okToRound = aPriority > newPriorityRounded && newPriorityRounded > bPriority;
603 ui.setPriority(task.getAttribute("id")!, okToRound ? newPriorityRounded : newPriority, model.getPriority(task));
604 task instanceof HTMLElement && task.focus();
607 setState: function (newState: string) {
608 const task = this.currentTask();
610 const oldState = task.getAttribute("data-state")!;
611 if (newState === oldState) return;
612 const createTimestamp = task.getAttribute("id")!;
613 if (currentViewState !== "all" || newState == "deleted") {
614 this.moveCursorVertically(1) || this.moveCursorVertically(-1);
616 return ui.setState(createTimestamp, newState, oldState);
619 setTagFilter: function (filter: TagFilter) {
620 if (currentTagFilter !== null) {
624 const tasksWithTag = new Map();
625 for (const task of document.getElementsByClassName("task")) {
626 if (filter.include(task)) {
627 tasksWithTag.set(task.getElementsByClassName("desc")[0].textContent, [model.getPriority(task), task]);
631 function highestPrioritySuperTask(t: Element) {
632 var maxPriority = -1;
633 var superTask = null;
634 for (const child of t.getElementsByClassName("tag")) {
635 const e = tasksWithTag.get(child.textContent);
636 if (e !== undefined && e[0] > maxPriority) {
644 for (const task of Array.from(document.getElementsByClassName("task"))) {
645 if (filter.include(task)) {
646 task.classList.remove("hide");
648 const superTask = highestPrioritySuperTask(task);
649 if (superTask !== null) {
650 model.insertInPriorityOrder(task, superTask);
652 task.classList.add("hide");
657 currentTagFilter = filter;
661 setTagView: function (tag: string | null = null) {
663 const target = this.currentTag();
665 tag = target.textContent!;
667 this.setTagFilter({description: tag, include: task => !!model.hasTag(task, tag!)});
670 setTitle: function () {
671 document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter.description : "");
674 setView: function (state: string) {
675 const sheet = (document.getElementById("viewStyle") as HTMLStyleElement).sheet!;
676 if (state === "all") {
677 sheet.insertRule(`.task[data-state=deleted] { display: none }`);
679 sheet.insertRule(`.task:not([data-state=${state}]) { display: none }`);
681 sheet.insertRule(`:root { --view-state-indicator-color: ${viewColors[state]}; }`);
684 currentViewState = state;
686 if (this.currentTask()?.getAttribute("data-state") !== state) {
687 this.firstVisibleTask()?.focus();
691 setUntaggedView: function () {
692 this.setTagFilter({description: "(untagged)", include: task => task.getElementsByClassName("tag").length === 0});
695 toggleDark: function () {
696 document.body.classList.toggle("dark");
697 this.setView(currentViewState);
701 const ret = ui.undo();
702 if (ret && ret instanceof HTMLElement) ret.focus();
705 const ret = ui.redo();
706 if (ret && ret instanceof HTMLElement) ret.focus();
710 const browserUI = BrowserUI();
712 const scrollIncrement = 60;
719 var inputState = InputState.Root;
720 var inputCount: number | null = null;
722 function handleKey(event: any) {
723 if (["Alt", "Control", "Meta", "Shift"].includes(event.key)) return;
724 if (event.target.tagName === "TEXTAREA") {
725 if (event.key == "Enter" && event.ctrlKey) return browserUI.completeContentEdit(event);
726 if (event.key == "Escape") return browserUI.completeContentEdit(event, CommitOrAbort.Abort);
727 } else if (event.target.tagName === "INPUT") {
728 if (event.target.id === "taskName") {
729 if (event.key == "Enter") return browserUI.addTask(event);
730 if (event.key == "Escape") return browserUI.returnFocusAfterInput();
731 } else if (event.target.classList.contains("tag")) {
732 if (event.key == "Enter") return browserUI.completeTagEdit(event);
733 if (event.key == "Escape") return browserUI.completeTagEdit(event, CommitOrAbort.Abort);
735 if (event.key == "Enter") return browserUI.completeEdit(event);
736 if (event.key == "Escape") return browserUI.completeEdit(event, CommitOrAbort.Abort);
739 if (inputState === InputState.Root) {
740 if ("0" <= event.key && event.key <= "9") {
741 return (inputCount = (inputCount ?? 0) * 10 + parseInt(event.key));
745 if (event.key == "e") return window.scrollBy(0, (inputCount ?? 1) * scrollIncrement);
746 if (event.key == "y") return window.scrollBy(0, (inputCount ?? 1) * -scrollIncrement);
748 if (event.key == "h") return browserUI.moveCursorLeft();
749 if (event.key == "l") return browserUI.moveCursorRight();
750 if (event.key == "j") return browserUI.moveCursorVertically(inputCount ?? 1);
751 if (event.key == "k") return browserUI.moveCursorVertically(-(inputCount ?? 1));
752 if (event.key == "J") return browserUI.moveTask(inputCount ?? 1);
753 if (event.key == "K") return browserUI.moveTask(-(inputCount ?? 1));
754 if (event.key == "G") return browserUI.jumpCursor(inputCount ?? MAX_SAFE_INTEGER);
755 if (event.key == "T") return browserUI.makeTopPriority();
756 if (event.key == "n") return browserUI.focusTaskNameInput(event);
757 if (event.key == "C") return browserUI.setState("cancelled");
758 if (event.key == "d") return browserUI.setState("done");
759 if (event.key == "q") return browserUI.setState("todo");
760 if (event.key == "s") return (inputState = InputState.S);
761 if (event.key == "w") return browserUI.setState("waiting");
762 if (event.key == "X") return browserUI.setState("deleted");
763 if (event.key == "x") return browserUI.removeTag();
764 if (event.key == "u") return browserUI.undo();
765 if (event.key == "r") return browserUI.redo();
766 if (event.key == "E") return browserUI.beginEditContent(event);
767 if (event.key == "e") return browserUI.beginEdit(event);
768 if (event.key == "t") return browserUI.beginTagEdit(event);
769 if (event.key == "v") return (inputState = InputState.V);
774 } else if (inputState === InputState.S) {
775 inputState = InputState.Root;
776 if (event.key == "m") return browserUI.setState("someday-maybe");
777 } else if (inputState === InputState.V) {
778 inputState = InputState.Root;
779 if (event.key == "a") return browserUI.setView("all");
780 if (event.key == "C") return browserUI.setView("cancelled");
781 if (event.key == "c") return browserUI.setTagView("comp");
782 if (event.key == "D") return browserUI.toggleDark();
783 if (event.key == "d") return browserUI.setView("done");
784 if (event.key == "e") return browserUI.setTagView("errand");
785 if (event.key == "h") return browserUI.setTagView("home");
786 if (event.key == "i") return browserUI.setUntaggedView();
787 if (event.key == "p") return browserUI.setTagView("Project");
788 if (event.key == "q") return browserUI.setView("todo");
789 if (event.key == "s") return (inputState = InputState.VS);
790 if (event.key == "T") return browserUI.resetTagView();
791 if (event.key == "t") return browserUI.setTagView();
792 if (event.key == "u") return browserUI.setUntaggedView();
793 if (event.key == "v") return browserUI.resetView();
794 if (event.key == "w") return browserUI.setView("waiting");
795 if (event.key == "x") return browserUI.setView("deleted");
796 if (event.key == "z") return browserUI.setTagView("zombie");
797 } else if (inputState === InputState.VS) {
798 inputState = InputState.Root;
799 if (event.key == "m") return browserUI.setView("someday-maybe");
804 function browserInit() {
806 browserUI.setTitle();
807 browserUI.firstVisibleTask()?.focus();
808 document.body.addEventListener("keydown", handleKey, { capture: false });