};
const BrowserUI = {
- addTask: function () {
+ addTask: function (event: KeyboardEvent) {
const input = <HTMLInputElement>document.getElementById("taskName");
if (input.value) {
const task = UI.addTask(input.value);
input.value = "";
+ if (event.getModifierState("Control")) {
+ this.setPriority(task, null, document.getElementsByClassName("task")[0]);
+ }
}
},
- destroyTask: function () {
- const createTimestamp = document.activeElement?.getAttribute("data-created");
- this.moveCursor(1) || this.moveCursor(-1);
- return UI.destroyTask(createTimestamp!);
+ firstVisibleTask: function () {
+ for (const task of document.getElementsByClassName("task")) {
+ if (task instanceof HTMLElement && task.style.display !== "none") {
+ return task;
+ }
+ }
},
- focusTaskNameInput: function (event: any) {
+ focusTaskNameInput: function (event: Event) {
document.getElementById("taskName")!.focus();
event.preventDefault();
},
function handleKey(event: any) {
if (event.target.tagName === "INPUT") {
- if (event.key == "Enter") return BrowserUI.addTask();
+ if (event.key == "Enter") return BrowserUI.addTask(event);
} else {
if (event.key == "j") return BrowserUI.moveCursor(1);
if (event.key == "k") return BrowserUI.moveCursor(-1);
function browserInit() {
document.body.addEventListener("keydown", handleKey, { capture: false });
log.replay();
+ BrowserUI.firstVisibleTask()?.focus();
}