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:36 +0300
committerGitHub <noreply@github.com>2025-06-20 21:35:36 +0300
commitf857a5fc9790b3841ab3f43020f755021a4c0003 (patch)
tree0264f1199fbc0f08c927634f5f1d6b42db665d5c /internal/task/task.go
parent62842fe088e54f3a034c9ee4166ac684b6bb38a7 (diff)
parent66e614304abec6132c88c3fe84f99dd9f960c90f (diff)
Merge pull request #49 from snonux/codex/add--started--tasks-to-sorting-order
Prioritize started tasks in sorting
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