ToDo - /Task Manager & Global Interactive Table Sorter & Filtering

The native "Task: Remove Completed" command only works for currently opened page.

But here is a space-lua script to Remove ALL completed task no matter on which page they are:

command.define {  
  name = "Task: Remove All Completed",  
  run = function()  
    -- Query all completed tasks across all pages  
    local completedTasks = query[[  
      from index.tag "task"  
      where _.done == true  
    ]]  
      
    local removedCount = 0  
      
    -- Group tasks by page to avoid reading the same page multiple times  
    local tasksByPage = {}  
    for _, task in ipairs(completedTasks) do  
      if not tasksByPage[task.page] then  
        tasksByPage[task.page] = {}  
      end  
      table.insert(tasksByPage[task.page], task)  
    end  
      
    -- Process each page  
    for pageName, pageTasks in pairs(tasksByPage) do  
      local text = space.readPage(pageName)  
        
      -- Sort tasks by position in reverse order to avoid offset issues  
      table.sort(pageTasks, function(a, b)  
        return (a.range and a.range[1] or a.pos) > (b.range and b.range[1] or b.pos)  
      end)  
        
      -- Remove each task from the page text  
      for _, task in ipairs(pageTasks) do  
        local startPos = task.range and task.range[1] or task.pos  
        local endPos = task.range and task.range[2] or task.pos  
          
        -- Remove the task line and the trailing newline in one swift motion
        text = text:sub(1, startPos) .. text:sub(endPos + 2)  
        removedCount = removedCount + 1  
      end  
        
      -- Write the modified page back  
      space.writePage(pageName, text)  
    end  
      
    editor.flashNotification("Removed " .. removedCount .. " completed tasks across all pages")  
  end  
}

Great, thank you

@Mr.Red This is a really impressive piece of work, very cool. Would you consider adding pieces of code from Another Take on Recurring Tasks? In my opinion, it would make a useful addition.

1 Like

I don’t use recurring tasks in Silverbullet but technically the task Manager could work with any task attribute, so you could easily edit the repeat, start and due date attribute from within the task manager already. So I don’t quite understand what do you mean? What code should I add to the task manager?