better way of checking done status
This commit is contained in:
parent
b38412a86e
commit
4d9482f363
18
bubbletea.go
18
bubbletea.go
@ -76,13 +76,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
// The "enter" key and the spacebar (a literal space) toggle
|
// The "enter" key and the spacebar (a literal space) toggle
|
||||||
// the selected state for the item that the cursor is pointing at.
|
// the selected state for the item that the cursor is pointing at.
|
||||||
case " ":
|
case " ":
|
||||||
_, ok := m.selected[m.cursor]
|
|
||||||
if ok {
|
if !m.addTask {
|
||||||
delete(m.selected, m.cursor)
|
if m.todos[m.cursor].done {
|
||||||
|
m.todos[m.cursor].done = false
|
||||||
} else {
|
} else {
|
||||||
m.selected[m.cursor] = struct{}{}
|
m.todos[m.cursor].done = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -138,8 +141,11 @@ func (m model) View() string {
|
|||||||
|
|
||||||
// Is this choice selected?
|
// Is this choice selected?
|
||||||
checked := " " // not selected
|
checked := " " // not selected
|
||||||
if _, ok := m.selected[i]; ok {
|
// if _, ok := m.selected[i]; ok {
|
||||||
checked = "x" // selected!
|
// checked = "x" // selected!
|
||||||
|
// }
|
||||||
|
if value.done {
|
||||||
|
checked = "x"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the row
|
// Render the row
|
||||||
|
Loading…
x
Reference in New Issue
Block a user