all repos — todo.txt-go @ 7def563420741ab6ef1577c7e3b04807f980eeb2

feat: :sparkles: Sort by priority or due date
Tim Izzo tim@octree.ch
Mon, 24 Mar 2025 22:07:58 +0100
commit

7def563420741ab6ef1577c7e3b04807f980eeb2

parent

afca122bfa3e223153006ae7ee265831fa699607

2 files changed, 32 insertions(+), 18 deletions(-)

jump to
M keymap.gokeymap.go

@@ -3,23 +3,24 @@

import "github.com/charmbracelet/bubbles/key" type keyMap struct { - Up key.Binding - Down key.Binding - Priority key.Binding - ClearPriority key.Binding - Help key.Binding - SaveQuit key.Binding - Quit key.Binding - Check key.Binding - Clean key.Binding - Add key.Binding - Sort key.Binding + Up key.Binding + Down key.Binding + Priority key.Binding + ClearPriority key.Binding + Help key.Binding + SaveQuit key.Binding + Quit key.Binding + Check key.Binding + Clean key.Binding + Add key.Binding + SortByPriority key.Binding + SortByDate key.Binding } // ShortHelp returns keybindings to be shown in the mini help view. It's part // of the key.Map interface. func (k keyMap) ShortHelp() []key.Binding { - return []key.Binding{k.Check, k.Add, k.Sort, k.SaveQuit, k.Help} + return []key.Binding{k.Check, k.Add, k.SortByPriority, k.SaveQuit, k.Help} } // FullHelp returns keybindings for the expanded help view. It's part of the

@@ -28,7 +29,7 @@ func (k keyMap) FullHelp() [][]key.Binding {

return [][]key.Binding{ {k.Check, k.Priority, k.Up}, {k.Add, k.ClearPriority, k.Clean, k.Down}, - {k.Sort, k.SaveQuit, k.Quit}, + {k.SortByPriority, k.SortByDate, k.SaveQuit, k.Quit}, } }

@@ -53,9 +54,13 @@ Add: key.NewBinding(

key.WithKeys("A", "+"), key.WithHelp("A|+", "Add new task"), ), - Sort: key.NewBinding( + SortByPriority: key.NewBinding( + key.WithKeys("p"), + key.WithHelp("p", "Sort by priority"), + ), + SortByDate: key.NewBinding( key.WithKeys("s"), - key.WithHelp("s", "Sort tasks"), + key.WithHelp("s", "Sort by date"), ), Help: key.NewBinding( key.WithKeys("?"),
M main.gomain.go

@@ -48,7 +48,7 @@ log.Fatal(err)

return model{} } else { tasks := tasklist - tasks.Sort(todo.SortCompletedDateAsc, todo.SortDueDateAsc, todo.SortPriorityAsc) + tasks.Sort(todo.SortCompletedDateAsc, todo.SortDueDateAsc) selected := make(map[int]struct{}) interfaceState := List

@@ -127,8 +127,17 @@ m.selected[m.cursor] = struct{}{}

m.tasks[m.cursor].Complete() } - case key.Matches(msg, m.keys.Sort): - m.tasks.Sort(todo.SortCompletedDateAsc, todo.SortDueDateAsc, todo.SortPriorityAsc) + case key.Matches(msg, m.keys.SortByPriority): + m.tasks.Sort(todo.SortCompletedDateAsc, todo.SortPriorityAsc) + m.selected = make(map[int]struct{}) + for i, t := range m.tasks { + if t.Completed { + m.selected[i] = struct{}{} + } + } + + case key.Matches(msg, m.keys.SortByDate): + m.tasks.Sort(todo.SortCompletedDateAsc, todo.SortDueDateAsc) m.selected = make(map[int]struct{}) for i, t := range m.tasks { if t.Completed {