From 803fc6a8d0e09b8b918b9ca5b7963672d8b13517 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Tue, 16 Oct 2018 14:25:08 -0600 Subject: Fix bug in computing added/removed labels --- termui/label_select.go | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'termui/label_select.go') diff --git a/termui/label_select.go b/termui/label_select.go index 5a0793f7..c4bf833d 100644 --- a/termui/label_select.go +++ b/termui/label_select.go @@ -288,28 +288,33 @@ func (ls *labelSelect) saveAndReturn(g *gocui.Gui, v *gocui.View) error { } } - // Find the new and removed labels. This makes use of the fact that the first elements - // of selectedLabels are the not-removed labels in bugLabels + // Find the new and removed labels. This could be implemented more efficiently... newLabels := []string{} rmLabels := []string{} - i := 0 // Index for bugLabels - j := 0 // Index for selectedLabels - for { - if j == len(selectedLabels) { - // No more labels to consider - break - } else if i == len(bugLabels) { - // Remaining labels are all new - newLabels = append(newLabels, selectedLabels[j].String()) - j += 1 - } else if bugLabels[i] == selectedLabels[j] { - // Labels match. Move to next pair - i += 1 - j += 1 - } else { - // Labels don't match. Prelabel must have been removed - rmLabels = append(rmLabels, bugLabels[i].String()) - i += 1 + + for _, selectedLabel := range selectedLabels { + found := false + for _, bugLabel := range bugLabels { + if selectedLabel == bugLabel { + found = true + } + } + + if !found { + newLabels = append(newLabels, string(selectedLabel)) + } + } + + for _, bugLabel := range bugLabels { + found := false + for _, selectedLabel := range selectedLabels { + if bugLabel == selectedLabel { + found = true + } + } + + if !found { + rmLabels = append(rmLabels, string(bugLabel)) } } -- cgit