ryangomba / obsidian-todo-sort

A plugin for Obsidian that sorts todos within a note
MIT License
12 stars 4 forks source link

Works only for - [x] but not for * [x] #5

Open henon opened 6 months ago

henon commented 6 months ago

Apparently, it is possible to create todo lists with both dashes and astersiks in Obsidian. If the styles are mixed which can happen if you convert bullet points into checkboxes with a hotkey then sorting doesn't work any more.

lilianzzz commented 1 month ago

Considering that MR was not accepted, I made a crutch. The code for editing the code in the plugin is directly ".obsidian\plugins\todo-sort\main.js"

// src/sort.ts
function sortTodos(plainText, sortOrder) {
  const lines = plainText.split("\n");
  const lineInfos = lines.map((value, originalIndex) => {
    let todoMatch = value.match(/^\s*[-*] \[(.)\]/i); // modify
    const todo = !!todoMatch;   // modify
    const completed = !!todoMatch && todoMatch[1] != " "; // modify
    const indentation = value.length - value.trimStart().length;
    return { originalIndex, value, todo, completed, indentation };
  });
  const sortedLineInfos = sortLineInfos(lineInfos, sortOrder);
  const lineMap = {};
  for (let i = 0; i < sortedLineInfos.length; i++) {
    const lineInfo = sortedLineInfos[i];
    lineMap[lineInfo.originalIndex] = i;
  }
  const output = sortedLineInfos.map((lineInfo) => lineInfo.value).join("\n");
  return { output, lineMap };
}