tu2-atmanand / Task-Board

An Obsidian plugin to view and manage all your task in a much more efficient Kanban Board format. Easily manage your tasks throught your vault.
https://tu2-atmanand.github.io/task-board-docs/
GNU General Public License v3.0
5 stars 0 forks source link

Tasks Deleting functionality not working after the subTasks feature has been integrated #25

Closed tu2-atmanand closed 1 month ago

tu2-atmanand commented 1 month ago

You will need to update the following function to detect first the complete task (Main task + Body + SubTasks) and then replace this with the empty charater.

export const deleteTaskFromFile = (task: Task) => {
    const basePath = (window as any).app.vault.adapter.basePath;
    const filePath = path.join(basePath, task.filePath);

    try {
        const fileContent = fs.readFileSync(filePath, "utf8");
        // Updated regex to match the task body ending with '|'
        const taskRegex = new RegExp(`^- \\[ \\] ${task.body} \\|.*`, "gm");
        const newContent = fileContent.replace(taskRegex, ""); // Remove the matched line from the file
        fs.writeFileSync(filePath, newContent);
    } catch (error) {
        console.error("Error deleting task from file:", error);
    }
};
tu2-atmanand commented 1 month ago

This issue has been resolved. Now i am detecting the complete body along with the main task and then replacing it with empty character.