summaryrefslogtreecommitdiff
path: root/internal/task/task.go
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 21:35:01 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 21:35:01 +0300
commit66e614304abec6132c88c3fe84f99dd9f960c90f (patch)
treeca6423fd4e139cb8f7c7509fb93961e93fc4d58f /internal/task/task.go
parentfe915c0c6eb7612bf645f55a99ac218df0e73ae8 (diff)
sort: prioritize started tasks
Diffstat (limited to 'internal/task/task.go')
-rw-r--r--internal/task/task.go11
1 files changed, 9 insertions, 2 deletions
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