Skip to content

Commit

Permalink
exotui: always push tag names onto the stack when changing tags (even…
Browse files Browse the repository at this point in the history
… if tag is deleted as we switch)
  • Loading branch information
neutralinsomniac committed Apr 4, 2020
1 parent 44035ce commit b491e7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 4 additions & 7 deletions cmd/exotui/exotui.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,10 @@ func (s *state) Refresh() {

func (s *state) SwitchTag(tag db.Tag) {
if tag.ID != s.CurrentDBTag.ID {
deleted, err := s.DeleteTagIfEmpty(s.CurrentDBTag.ID)
err := s.DeleteTagIfEmpty(s.CurrentDBTag.ID)
checkErr(err)
// if we're switching to a new tag, and this tag didn't just get wiped,
// push it onto our tag stack
if !deleted {
s.tagStack = append(s.tagStack, s.CurrentDBTag.Name)
}
// if we're switching to a new tag, push it onto our tag stack
s.tagStack = append(s.tagStack, s.CurrentDBTag.Name)
}

s.CurrentDBTag = tag
Expand All @@ -128,7 +125,7 @@ func (s *state) PopTag() {

// have to do the manual tag switch dance since SwitchTag() will push onto the tag stack
if tag.ID != s.CurrentDBTag.ID {
_, err := s.DeleteTagIfEmpty(s.CurrentDBTag.ID)
err := s.DeleteTagIfEmpty(s.CurrentDBTag.ID)
checkErr(err)
}

Expand Down
7 changes: 2 additions & 5 deletions db/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ End:
return err
}

func (s *State) DeleteTagIfEmpty(id int64) (bool, error) {
func (s *State) DeleteTagIfEmpty(id int64) error {
var rows []Row
var refs Refs
var err error

deleted := false

rows, err = s.DB.GetRowsForTagID(id)
if err != nil {
goto End
Expand All @@ -63,9 +61,8 @@ func (s *State) DeleteTagIfEmpty(id int64) (bool, error) {

if len(rows)+len(refs) == 0 {
err = s.DB.DeleteTagByID(id)
deleted = true
}

End:
return deleted, err
return err
}

0 comments on commit b491e7b

Please sign in to comment.