Skip to content

Commit

Permalink
fix: un-break initializing a player
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Sep 6, 2024
1 parent bd15c2b commit f058f4c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pkg/replay/player/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ func (p *Player) GotoProgress(
}
}

isBeginning := fromIndex == 0 && fromByte == 0
// Going back in time; must start over
if toIndex < fromIndex || (toIndex == fromIndex && toByte < fromByte) {
isBefore := toIndex < fromIndex || (toIndex == fromIndex && toByte < fromByte)

if isBefore || isBeginning {
p.resetTerminal()
fromIndex = 0
fromByte = -1
Expand All @@ -67,23 +70,27 @@ func (p *Player) GotoProgress(
case P.OutputMessage:
data := e.Data

if len(data) > 0 {
if fromIndex == toIndex {
data = data[fromByte+1 : toByte+1]
} else if fromIndex == i {
data = data[fromByte+1:]
} else if toIndex == i {
data = data[:toByte+1]
}
if len(data) == 0 {
continue
}

if fromIndex == toIndex {
data = data[fromByte+1 : toByte+1]
} else if fromIndex == i {
data = data[fromByte+1:]
} else if toIndex == i {
data = data[:toByte+1]
}

if len(data) > 0 {
// Need to clear dirty state before every write
// so that the detector works
p.Terminal.Changes().Reset()
p.Terminal.Parse(data)
if len(data) == 0 {
continue
}

// Need to clear dirty state before every write
// so that the detector works
p.Terminal.Changes().Reset()
p.Terminal.Parse(data)

if i >= p.nextDetect {
p.detector.Detect(p.Terminal, p.events)
p.nextDetect = i + 1
Expand Down

0 comments on commit f058f4c

Please sign in to comment.