-const BrowserUI = {
- 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();
- input.value = "";
- if (event.getModifierState("Control")) {
- this.setPriority(task, null, document.getElementsByClassName("task")[0]);
+ beginEdit: function (event: Event) {
+ const task = document.activeElement;
+ if (!task) return;
+ const input = document.createElement("input");
+ const oldDescription = task.textContent!;
+ task.setAttribute("data-description", oldDescription);
+ input.value = oldDescription;
+ input.addEventListener("blur", this.completeEdit, { once: true });
+ task.textContent = "";
+ task.appendChild(input);
+ input.focus();
+ input.select();
+ event.preventDefault();
+ },
+
+ completeEdit: function (event: Event) {
+ 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.removeChild(task.children[0]);
+ task.removeAttribute("data-description");
+ task.focus();
+ if (newDescription === oldDescription) {
+ task.textContent = oldDescription;
+ } else {
+ ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);