From edec7717bdea74d11ec806ad5a98e26e9d3b7d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Fri, 20 Jun 2025 20:34:53 +0300 Subject: fix annotation replacement --- internal/task/task.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'internal/task') diff --git a/internal/task/task.go b/internal/task/task.go index f328838..fb07333 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -171,8 +171,15 @@ func Annotate(id int, text string) error { } // Denotate removes an annotation from the task with the given id. -func Denotate(id int, annoID int) error { - return run(strconv.Itoa(id), "denotate", strconv.Itoa(annoID)) +// Denotate removes an annotation from the task with the given id. The +// annotation text is matched exactly when provided. If text is empty, the +// oldest annotation is removed. +func Denotate(id int, text string) error { + args := []string{strconv.Itoa(id), "denotate"} + if text != "" { + args = append(args, text) + } + return run(args...) } // ReplaceAnnotations removes all existing annotations from the task with the @@ -187,8 +194,8 @@ func ReplaceAnnotations(id int, text string) error { return fmt.Errorf("task %d not found", id) } anns := tasks[0].Annotations - for i := len(anns); i >= 1; i-- { - if err := Denotate(id, i); err != nil { + for i := len(anns) - 1; i >= 0; i-- { + if err := Denotate(id, anns[i].Description); err != nil { return err } } -- cgit v1.2.3