Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit e05b50c

Browse files
authored
Merge pull request #45 from howeyc/nil-active
stop assuming always active window, fixes #15
2 parents 9da116f + e816cbc commit e05b50c

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

show.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func NewAggTime(stream *Stream, labelFunc func(*Window) string) *AggTime {
4444
windows[win.ID] = win
4545
}
4646

47-
active.Plus(labelFunc(windows[snap.Active]), 1)
47+
if win := windows[snap.Active]; win != nil {
48+
active.Plus(labelFunc(windows[snap.Active]), 1)
49+
}
4850
for _, v := range snap.Visible {
4951
visible.Plus(labelFunc(windows[v]), 1)
5052
}
@@ -138,17 +140,20 @@ func NewTimeline(stream *Stream, labelFunc func(*Window) string) *Timeline {
138140
}
139141

140142
{
141-
win := windows[snap.Active]
142-
winLabel := labelFunc(win)
143-
if lastActive != nil && lastActive.Label == winLabel {
144-
lastActive.End = snap.Time
145-
} else {
146-
if lastActive != nil {
143+
if win := windows[snap.Active]; win != nil {
144+
winLabel := labelFunc(win)
145+
if lastActive != nil && lastActive.Label == winLabel {
147146
lastActive.End = snap.Time
147+
} else {
148+
if lastActive != nil {
149+
lastActive.End = snap.Time
150+
}
151+
newRange := &Range{Label: winLabel, Start: snap.Time, End: snap.Time}
152+
active = append(active, newRange)
153+
lastActive = newRange
148154
}
149-
newRange := &Range{Label: winLabel, Start: snap.Time, End: snap.Time}
150-
active = append(active, newRange)
151-
lastActive = newRange
155+
} else {
156+
lastActive = nil
152157
}
153158
}
154159

0 commit comments

Comments
 (0)