addTask: function (timestamp: string, description: string): Element {
const task = document.createElement("div");
task.appendChild(document.createTextNode(description));
addTask: function (timestamp: string, description: string): Element {
const task = document.createElement("div");
task.appendChild(document.createTextNode(description));
task.setAttribute("tabindex", "0");
task.setAttribute("data-created", timestamp);
task.setAttribute("data-state", "todo");
task.setAttribute("tabindex", "0");
task.setAttribute("data-created", timestamp);
task.setAttribute("data-state", "todo");
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.
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.
input.selectionEnd === input.value.length
) {
// No local changes have actually been made yet. Change the contents of the edit box!
input.value = newDescription;
input.selectionEnd === input.value.length
) {
// No local changes have actually been made yet. Change the contents of the edit box!
input.value = newDescription;
const [createTimestamp, description] = splitN(data, " ", 1);
return Model.edit(createTimestamp, description);
}
const [createTimestamp, description] = splitN(data, " ", 1);
return Model.edit(createTimestamp, description);
}
- if (command == "State") {
- const [createTimestamp, state] = splitN(data, " ", 1);
- return Model.setState(timestamp, createTimestamp, state);
- }
if (command == "Priority") {
const [createTimestamp, newPriority] = splitN(data, " ", 1);
return Model.setPriority(createTimestamp, parseFloat(newPriority));
}
if (command == "Priority") {
const [createTimestamp, newPriority] = splitN(data, " ", 1);
return Model.setPriority(createTimestamp, parseFloat(newPriority));
}
+ if (command == "State") {
+ const [createTimestamp, state] = splitN(data, " ", 1);
+ return Model.setState(timestamp, createTimestamp, state);
+ }
return {
addTask: function (event: KeyboardEvent) {
const input = <HTMLInputElement>document.getElementById("taskName");
if (input.value) {
const task = ui.addTask(input.value);
return {
addTask: function (event: KeyboardEvent) {
const input = <HTMLInputElement>document.getElementById("taskName");
if (input.value) {
const task = ui.addTask(input.value);
- if (task && task instanceof HTMLElement) task.focus();
+ if (currentViewState === "todo") {
+ task instanceof HTMLElement && task.focus();
+ } else if (this.returnFocusAfterInput()) {
+ } else {
+ this.firstVisibleTask()?.focus();
+ }
input.value = "";
if (event.getModifierState("Control")) {
this.setPriority(task, null, document.getElementsByClassName("task")[0]);
input.value = "";
if (event.getModifierState("Control")) {
this.setPriority(task, null, document.getElementsByClassName("task")[0]);
const input = event.target as HTMLInputElement;
const task = input.parentElement!;
const oldDescription = task.getAttribute("data-description")!;
const newDescription = input.value;
input.removeEventListener("blur", this.completeEdit);
const input = event.target as HTMLInputElement;
const task = input.parentElement!;
const oldDescription = task.getAttribute("data-description")!;
const newDescription = input.value;
input.removeEventListener("blur", this.completeEdit);
task.textContent = oldDescription;
} else {
ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
task.textContent = oldDescription;
} else {
ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
// 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);
// 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);
if (event.target.tagName === "INPUT") {
if (event.target.id === "taskName") {
if (event.key == "Enter") return browserUI.addTask(event);
if (event.target.tagName === "INPUT") {
if (event.target.id === "taskName") {
if (event.key == "Enter") return browserUI.addTask(event);
if (event.key == "n") return browserUI.focusTaskNameInput(event);
if (event.key == "c") return browserUI.setState("cancelled");
if (event.key == "d") return browserUI.setState("done");
if (event.key == "n") return browserUI.focusTaskNameInput(event);
if (event.key == "c") return browserUI.setState("cancelled");
if (event.key == "d") return browserUI.setState("done");
if (event.key == "w") return browserUI.setState("waiting");
if (event.key == "X") return browserUI.setState("deleted");
if (event.key == "u") return browserUI.undo();
if (event.key == "w") return browserUI.setState("waiting");
if (event.key == "X") return browserUI.setState("deleted");
if (event.key == "u") return browserUI.undo();
inputState = InputState.Command;
if (event.key == "c") return browserUI.setView("cancelled");
if (event.key == "d") return browserUI.setView("done");
inputState = InputState.Command;
if (event.key == "c") return browserUI.setView("cancelled");
if (event.key == "d") return browserUI.setView("done");
if (event.key == "w") return browserUI.setView("waiting");
if (event.key == "x") return browserUI.setView("deleted");
}
if (event.key == "w") return browserUI.setView("waiting");
if (event.key == "x") return browserUI.setView("deleted");
}