Skip to content

Commit 67683dc

Browse files
committed
HoverTime: fix redraw problem across unknown duration
When duration went to 0 and then came back with the same value it had previously (e.g. playing the same video twice in a row), the time would change to ???? and not change back to a timestamp until the mouse was moved. This happened because the computed hover timestamp did not get updated during the portion of unknown duration, so the value was cached too aggressively. By decoupling the positioning logic from the timestamp logic, the intent becomes more obvious and hopefully less bug-prone.
1 parent 7459d8a commit 67683dc

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/HoverTime.moon

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,40 @@ class HoverTime extends BarAccent
4040
@line[2] = ("%g,%g")\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @position
4141
@needsUpdate = true
4242

43+
_setXPosition: (x) =>
44+
@line[2] = ("%g,%g")\format clamp( x, leftMargin, Window.w - rightMargin ), @position
45+
@needsUpdate = true
46+
47+
_setUnknownDuration: =>
48+
@line[4] = "????"
49+
@needsUpdate = true
50+
51+
_setTime: ( hoverTime ) =>
52+
@line[4] = ([[%d:%02d:%02d]])\format(
53+
math.floor( hoverTime / 3600 ),
54+
math.floor( (hoverTime / 60) % 60 ),
55+
math.floor( hoverTime % 60 )
56+
)
57+
@needsUpdate = true
58+
4359
redraw: =>
4460
if @active
4561
super!
4662

4763
duration = mp.get_property_number( 'duration', 0 )
64+
hoverTime = duration * Mouse.x / Window.w
4865

49-
if Mouse.x != @lastX or duration != @lastDuration
50-
@lastDuration = duration
51-
52-
@line[2] = ("%g,%g")\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @position
66+
if Mouse.x != @lastX
5367
@lastX = Mouse.x
68+
@_setXPosition( Mouse.x )
69+
70+
if duration != @lastDuration or hoverTime != @lastTime
71+
@lastDuration = duration
72+
@lastTime = hoverTime
5473

5574
if duration == 0
56-
@line[4] = "????"
75+
@_setUnknownDuration!
5776
else
58-
hoverTime = duration * Mouse.x / Window.w
59-
if hoverTime != @lastTime
60-
@line[4] = ([[%d:%02d:%02d]])\format math.floor( hoverTime / 3600 ), math.floor( (hoverTime / 60) % 60 ), math.floor( hoverTime % 60 )
61-
@lastTime = hoverTime
62-
63-
@needsUpdate = true
77+
@_setTime( hoverTime )
6478

6579
return @needsUpdate

0 commit comments

Comments
 (0)