From 66e614304abec6132c88c3fe84f99dd9f960c90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Fri, 20 Jun 2025 21:35:01 +0300 Subject: sort: prioritize started tasks --- internal/task/task.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'internal/task/task.go') diff --git a/internal/task/task.go b/internal/task/task.go index 4bd72c1..9c715c8 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -240,8 +240,9 @@ func Edit(id int) error { return EditCmd(id).Run() } -// SortTasks orders tasks by priority, due date, tag names and id. -// Tasks without a due date are placed after tasks with a due date. +// SortTasks orders tasks by start status, priority, due date, tag names and id. +// Started tasks are always placed before non-started ones. Tasks without a due +// date are placed after tasks with a due date. func SortTasks(tasks []Task) { joinTags := func(tags []string) string { if len(tags) == 0 { @@ -279,6 +280,12 @@ func SortTasks(tasks []Task) { sort.Slice(tasks, func(i, j int) bool { ti, tj := tasks[i], tasks[j] + startedI := ti.Start != "" && ti.Status != "completed" + startedJ := tj.Start != "" && tj.Status != "completed" + if startedI != startedJ { + return startedI + } + pi, pj := priVal(ti.Priority), priVal(tj.Priority) if pi != pj { return pi > pj -- cgit v1.2.3