summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 21:02:52 +0300
committerGitHub <noreply@github.com>2025-06-20 21:02:52 +0300
commit8de85810e32076b1e81588b2405e78bdefe94c93 (patch)
tree9f071f3699bdcee5f1a687383b9ee3dbba060f5e
parent3670a1b978e84f74d210b2432fa6b10d3b29d4ce (diff)
parentb6aabea328864b27a728240c2aa8794035a47243 (diff)
Merge pull request #38 from snonux/codex/change-sorting-order-by-pri-and-due-date
Adjust sort order to prioritize priority
-rw-r--r--internal/task/sort_test.go2
-rw-r--r--internal/task/task.go12
2 files changed, 7 insertions, 7 deletions
diff --git a/internal/task/sort_test.go b/internal/task/sort_test.go
index 4b034c9..10c1a12 100644
--- a/internal/task/sort_test.go
+++ b/internal/task/sort_test.go
@@ -21,7 +21,7 @@ func TestSortTasks(t *testing.T) {
for _, tsk := range tasks {
ids = append(ids, tsk.ID)
}
- want := []int{1, 5, 6, 4, 2, 3}
+ want := []int{1, 5, 6, 2, 4, 3}
if !reflect.DeepEqual(ids, want) {
t.Fatalf("unexpected order: %v", ids)
}
diff --git a/internal/task/task.go b/internal/task/task.go
index 55e1328..d878610 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -235,7 +235,7 @@ func Edit(id int) error {
return EditCmd(id).Run()
}
-// SortTasks orders tasks by due date, priority, tag names and id.
+// SortTasks orders tasks by priority, due date, tag names and id.
// Tasks without a due date are placed after tasks with a due date.
func SortTasks(tasks []Task) {
joinTags := func(tags []string) string {
@@ -274,6 +274,11 @@ func SortTasks(tasks []Task) {
sort.Slice(tasks, func(i, j int) bool {
ti, tj := tasks[i], tasks[j]
+ pi, pj := priVal(ti.Priority), priVal(tj.Priority)
+ if pi != pj {
+ return pi > pj
+ }
+
di, iok := parseDue(ti.Due)
dj, jok := parseDue(tj.Due)
if iok && !jok {
@@ -286,11 +291,6 @@ func SortTasks(tasks []Task) {
return di.Before(dj)
}
- pi, pj := priVal(ti.Priority), priVal(tj.Priority)
- if pi != pj {
- return pi > pj
- }
-
tgI, tgJ := joinTags(ti.Tags), joinTags(tj.Tags)
if tgI != tgJ {
return tgI < tgJ