Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
henon opened this issue Mar 8, 2024 · 1 comment
Open

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

henon opened this issue Mar 8, 2024 · 1 comment

Comments

@henon
Copy link

henon commented Mar 8, 2024

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
Copy link

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 };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants