Skip to content

Commit

Permalink
fix: don't reinit player if already at correct loc
Browse files Browse the repository at this point in the history
It's surprising this wasn't handled already, but we were erroneously
replaying the entire history of the pane every time replay mode was
opened in an existing pane.
  • Loading branch information
cfoust committed Sep 6, 2024
1 parent 7f74d5d commit bd15c2b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions pkg/replay/player/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func (p *Player) GotoProgress(
p.mu.Lock()
defer p.mu.Unlock()

defer func() {
if progress != nil {
close(progress)
}
}()

numEvents := len(p.events)
if numEvents == 0 {
return
Expand All @@ -30,6 +36,22 @@ func (p *Player) GotoProgress(
fromByte := p.location.Offset
toByte := offset

// Resolve toByte to an actual byte offset
switch e := p.events[toIndex].Message.(type) {
case P.OutputMessage:
if toByte < 0 {
toByte += len(e.Data)
}
toByte = geom.Clamp(toByte, 0, len(e.Data)-1)
if fromIndex == toIndex && fromByte == toByte {
return
}
case P.SizeMessage:
if fromIndex == toIndex {
return
}
}

// Going back in time; must start over
if toIndex < fromIndex || (toIndex == fromIndex && toByte < fromByte) {
p.resetTerminal()
Expand All @@ -45,13 +67,6 @@ func (p *Player) GotoProgress(
case P.OutputMessage:
data := e.Data

if toIndex == i {
if toByte < 0 {
toByte += len(data)
}
toByte = geom.Clamp(toByte, 0, len(data)-1)
}

if len(data) > 0 {
if fromIndex == toIndex {
data = data[fromByte+1 : toByte+1]
Expand Down Expand Up @@ -89,10 +104,6 @@ func (p *Player) GotoProgress(
oldProgress = newProgress
}

if progress != nil {
close(progress)
}

p.location.Index = toIndex
p.location.Offset = toByte
return
Expand Down

0 comments on commit bd15c2b

Please sign in to comment.