From 4d9482f36363bcb93d287fce5b37ad6ca64b82b6 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 17:39:03 +1300 Subject: [PATCH] better way of checking done status --- bubbletea.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bubbletea.go b/bubbletea.go index fea7c22..3924ed7 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -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