keep the block in place when the anchor is removed while a queued track plays

`adjustAnchorOnRemove` moved the anchor to the canonical predecessor of the
removed track, which in a shuffled queue is an unrelated play position, so
removing the context anchor while playing a queued track teleported the
up-next block somewhere random (and out of view).

When the removed context track is the anchor, move the anchor to the track
before it in play order (or -1), so the block stays where it sits. This also
covers removing the playing context anchor, so the controller's separate
re-anchor is no longer needed and is removed.
This commit is contained in:
austinried
2026-10-04 00:30:01 +00:00
parent 72330387c8
commit b21c297964
3 changed files with 35 additions and 13 deletions
@@ -1670,6 +1670,32 @@ class PlaybackControllerTest {
)
}
@Test
fun removingTheAnchorWhilePlayingABlockTrackKeepsTheBlockInPlace() {
seedShuffledQueue(seed = 5L)
seedSong("x1", "al2")
controller.addToQueue(1, QueueKind.Song, "x1")
await { runBlocking { controller.upcomingItem()?.id } == "x1" }
controller.playAt(1)
await {
controller.state.value.item
?.id == "x1"
}
val before = runBlocking { queues.snapshot() }
runBlocking { controller.removeAt(before.anchorPlay) }
val after = runBlocking { queues.snapshot() }
assertEquals(-1L, after.anchorPlay)
assertEquals("x1", runBlocking { queues.itemAt(after, 0)?.song?.id })
assertEquals(
"x1",
controller.state.value.item
?.id,
)
}
@Test
fun removingThePlayingTrackWhileShuffledPlaysTheNextShuffledTrack() {
seedShuffledQueue(seed = 12345L)