summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 21:25:25 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 21:25:25 +0300
commit8e3f1bea410eca250b80e3d4b045f68278aa7f58 (patch)
tree555462fad6da32f7b5221a2c0b3c017d7713a793
parent1989b6a3d4339321797a442d2fa2bbee21e23cd1 (diff)
Fix undo for completed tasks
-rw-r--r--internal/task/task.go5
-rw-r--r--internal/ui/table.go13
-rw-r--r--internal/ui/table_test.go4
3 files changed, 16 insertions, 6 deletions
diff --git a/internal/task/task.go b/internal/task/task.go
index d878610..4bd72c1 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -113,6 +113,11 @@ func SetStatus(id int, status string) error {
return run(strconv.Itoa(id), "modify", "status:"+status)
}
+// SetStatusUUID changes the status of the task with the given UUID.
+func SetStatusUUID(uuid, status string) error {
+ return run(uuid, "modify", "status:"+status)
+}
+
// Start begins the task with the given id.
func Start(id int) error {
return run(strconv.Itoa(id), "start")
diff --git a/internal/ui/table.go b/internal/ui/table.go
index b175776..e293325 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -39,7 +39,7 @@ type Model struct {
filters []string
tasks []task.Task
- undoStack []int
+ undoStack []string
total int
inProgress int
@@ -224,15 +224,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
idStr := ansi.Strip(row[0])
if id, err := strconv.Atoi(idStr); err == nil {
task.Done(id)
- m.undoStack = append(m.undoStack, id)
+ for _, tsk := range m.tasks {
+ if tsk.ID == id {
+ m.undoStack = append(m.undoStack, tsk.UUID)
+ break
+ }
+ }
m.reload()
}
}
case "U":
if n := len(m.undoStack); n > 0 {
- id := m.undoStack[n-1]
+ uuid := m.undoStack[n-1]
m.undoStack = m.undoStack[:n-1]
- task.SetStatus(id, "pending")
+ task.SetStatusUUID(uuid, "pending")
m.reload()
}
case "d":
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index 1161ec2..c1862d2 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -202,7 +202,7 @@ func TestUndoHotkey(t *testing.T) {
os.Unsetenv("TASKRC")
})
- m, err := New("")
+ m, err := New(nil)
if err != nil {
t.Fatalf("New: %v", err)
}
@@ -224,7 +224,7 @@ func TestUndoHotkey(t *testing.T) {
if lines[0] != "1 done" {
t.Fatalf("done not called: %q", lines[0])
}
- if lines[1] != "1 modify status:pending" {
+ if lines[1] != "x modify status:pending" {
t.Fatalf("undo not called: %q", lines[1])
}
}