Move sub-done todos to done

This commit is contained in:
Corey Johnson 2025-07-10 15:24:15 -07:00
parent 6f98a458b5
commit 527ecf6146

View File

@ -130,10 +130,9 @@ const moveToDone = (view: EditorView) => {
const doneTodos: Todo[] = []
todoList.forEach((header) => {
header.todos = header.todos.filter((todo) => {
if (typeof todo === "string" || !todo.done) return true
doneTodos.push(todo)
return false
if (typeof todo === "string") return true
doneTodos.push(...collectDoneTodos(todo))
return !todo.done
})
})
@ -147,6 +146,24 @@ const moveToDone = (view: EditorView) => {
})
}
const collectDoneTodos = (todo: Todo | string): Todo[] => {
if (typeof todo === "string") return []
const doneTodos: Todo[] = []
if (todo.done) {
todo.indent = ""
doneTodos.push(todo)
} else {
todo.children = todo.children.filter((child) => {
if (typeof child === "string") return true
doneTodos.push(...collectDoneTodos(child))
return !child.done
})
}
return doneTodos
}
const toggleDone = (view: EditorView) => {
const { state } = view
const { head } = state.selection.main