aboutsummaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorLuke Adams <lukeclydeadams@gmail.com>2018-10-16 14:25:08 -0600
committerLuke Adams <lukeclydeadams@gmail.com>2018-10-16 14:36:57 -0600
commit803fc6a8d0e09b8b918b9ca5b7963672d8b13517 (patch)
tree58cdd751033d0427e6f61597c1aa849735b82242 /termui
parent3eedb6f65a5951d43ed463c8959443ad7e59cc1a (diff)
downloadgit-bug-803fc6a8d0e09b8b918b9ca5b7963672d8b13517.tar.gz
Fix bug in computing added/removed labels
Diffstat (limited to 'termui')
-rw-r--r--termui/label_select.go45
1 files changed, 25 insertions, 20 deletions
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))
}
}