better way of checking done status

This commit is contained in:
june 2025-03-10 17:39:03 +13:00
parent b38412a86e
commit 4d9482f363
Signed by untrusted user who does not match committer: breadone
GPG Key ID: FDC19FE143200483

View File

@ -76,12 +76,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// The "enter" key and the spacebar (a literal space) toggle
// the selected state for the item that the cursor is pointing at.
case " ":
_, ok := m.selected[m.cursor]
if ok {
delete(m.selected, m.cursor)
} else {
m.selected[m.cursor] = struct{}{}
if !m.addTask {
if m.todos[m.cursor].done {
m.todos[m.cursor].done = false
} else {
m.todos[m.cursor].done = true
}
}
}
}
@ -138,8 +141,11 @@ func (m model) View() string {
// Is this choice selected?
checked := " " // not selected
if _, ok := m.selected[i]; ok {
checked = "x" // selected!
// if _, ok := m.selected[i]; ok {
// checked = "x" // selected!
// }
if value.done {
checked = "x"
}
// Render the row