fixed multiview bug and task name typing bug

This commit is contained in:
poanse 2026-05-03 00:28:25 +03:00
parent b420ac94d1
commit c4036d0ae2
6 changed files with 36 additions and 33 deletions

View file

@ -263,6 +263,7 @@ export class Context {
this.versionedData.changeParent(this.reparentingTaskId, newParentId);
this.updateTaskPositions();
this.cancelReparenting();
this.selectedTaskId = NoTaskId;
}
public changeFocusedTask(taskId: TaskId): void {
@ -454,14 +455,6 @@ export class Context {
this.save();
}
public hideTaskBranch(id: number) {
this.versionedData.setHidden(id, true);
}
public unhideTaskBranch(id: number) {
this.versionedData.setHidden(id, false);
}
public getCurrentTaskPosition(taskId: number) {
return this.taskPositions.find((t) => t.taskId === taskId)!.tween!
.current;

View file

@ -73,7 +73,10 @@ export class TaskmapView extends TextFileView {
protected onOpen(): Promise<void> {
this.registerEvent(
this.app.vault.on("modify", async (file) => {
if (file.path === this.file?.path) {
if (
file.path === this.file?.path &&
this.app.workspace.getActiveViewOfType(TaskmapView) != this
) {
await this.refreshUi(false);
}
}),

View file

@ -38,7 +38,7 @@ export class AddTaskAction implements Action {
if (data.curTaskId != this.addedTaskId + 1) {
throw new Error();
}
data.removeTask(this.addedTaskId);
data.removeTask();
this.addedTaskId = undefined;
}
}
@ -68,9 +68,9 @@ export class RemoveTaskSingleAction implements Action {
t.parentId = parentTask.taskId;
t.depth = parentTask.depth + 1;
});
// TODO: Priorities suck
data.recalcPriorities(task.parentId);
data.recalcStatusRecursive(task.parentId);
data.markTasksUpdated();
}
undo(data: ProjectData) {
@ -84,7 +84,6 @@ export class RemoveTaskSingleAction implements Action {
t.parentId = task.taskId;
t.depth = task.depth + 1;
});
// TODO: Priorities suck
data.recalcPriorities(task.parentId);
data.recalcPriorities(task.taskId);
data.recalcStatusRecursive(task.taskId);

View file

@ -7,7 +7,6 @@ export class HistoryManager {
execute(action: Action, data: ProjectData): void {
action.do(data);
data.markTasksUpdated();
this.undoStack.push(action);
this.redoStack = []; // Clear redo stack on new action
}
@ -17,7 +16,6 @@ export class HistoryManager {
if (!action) return false;
action.undo(data);
data.markTasksUpdated();
this.redoStack.push(action);
return true;
}
@ -27,7 +25,6 @@ export class HistoryManager {
if (!action) return false;
action.do(data);
data.markTasksUpdated();
this.undoStack.push(action);
return true;
}

View file

@ -9,12 +9,14 @@ import { NoTaskId, RootTaskId } from "../NodePositionsCalculator";
import type { ProjectFileParsed } from "./ProjectDataSchema";
export class ProjectData {
tasks = new SvelteMap<TaskId, TaskData>();
// cannot use just SvelteMap<TaskId, Task> because it breaks reactivity
tasks: Array<TaskData>;
taskIndexCache = new SvelteMap<TaskId, number>();
childrenCache = new SvelteMap<TaskId, TaskId[]>();
ancestorsCache = new SvelteMap<TaskId, TaskId[]>();
descendantsCache = new SvelteMap<TaskId, TaskId[]>();
tasksVersion = $state(0);
blockerPairs = $state(new Array<BlockerPair>());
tasksVersion: number;
blockerPairs: Array<BlockerPair>;
folderPath: string | undefined;
curTaskId = RootTaskId;
@ -28,16 +30,15 @@ export class ProjectData {
}
constructor(obj: ProjectFileParsed) {
this.tasks = new SvelteMap(
obj.tasks.map((task) => [task.taskId, task]),
);
if (this.tasks.size == 0) {
this.tasks = $state(obj.tasks);
this.blockerPairs = $state(obj.blockerPairs ?? []);
this.tasksVersion = $state(0);
this.folderPath = obj.folderPath;
this.curTaskId = obj.curTaskId;
if (this.tasks.length == 0) {
this.addRootTask();
}
this.rebuildCaches();
this.blockerPairs = obj.blockerPairs ?? [];
this.folderPath = obj.folderPath;
this.curTaskId = obj.curTaskId;
}
public markTasksUpdated() {
@ -45,6 +46,10 @@ export class ProjectData {
}
private rebuildCaches() {
this.taskIndexCache.clear();
this.tasks.forEach((value, index) => {
this.taskIndexCache.set(value.taskId, index);
});
// Order matters: descendants rely on ancestors, and ancestors rely on children.
this.rebuildChildrenCache();
this.rebuildAncestorsCache();
@ -103,17 +108,19 @@ export class ProjectData {
}
public addTask(task: TaskData) {
this.tasks.set(task.taskId, task);
this.tasks.push(task);
this.rebuildCaches();
this.markTasksUpdated();
this.curTaskId++;
}
public removeTask(taskId: TaskId) {
this.tasks.delete(taskId);
this.rebuildCaches();
this.markTasksUpdated();
this.curTaskId--;
public removeTask() {
const task = this.tasks.pop();
if (task) {
this.rebuildCaches();
this.markTasksUpdated();
this.curTaskId--;
}
}
public addRootTask() {
@ -159,7 +166,7 @@ export class ProjectData {
}
public getTask(taskId: number) {
const res = this.tasks.get(taskId);
const res = this.tasks[this.taskIndexCache.get(taskId)!];
if (res) {
return res;
} else {

View file

@ -145,7 +145,11 @@ export class VersionedData {
};
public getTaskOption = (taskId: TaskId) => {
return this.data.tasks.get(taskId);
try {
return this.data.getTask(taskId);
} catch {
return undefined;
}
};
public getChildren = (taskId: TaskId, includeDeleted?: boolean) => {