keep lastPosition in sync when a track move or delete shifts the current

move/removeAt/undo (and the window shift) changed the current track's
position without updating lastPosition, so the next transition compared
against a stale position and consumed whatever now sat there — moving a
queued track in front of the playing one deleted the moved track on the
following skip. Added an eager-dispatcher regression test.
This commit is contained in:
austinried
2026-10-04 00:30:00 +00:00
parent e23f78aa47
commit 3e459e4c84
2 changed files with 94 additions and 0 deletions
@@ -337,6 +337,7 @@ class PlaybackController(
if (wasUpNext) queueRepository.combinedIndexOf(updated, it) else queueRepository.combinedContextIndexOf(updated, it)
} ?: (if (position < current) current - 1 else current)
).coerceIn(0, updated.size - 1)
lastPosition = target
lastEdit =
if (removed == null) {
ReloadUndo(entries, cursor, snapshot.shuffleOrder, upNext, snapshot.upNextAnchor)
@@ -390,6 +391,7 @@ class PlaybackController(
if (!queueRepository.move(snapshot, from, to)) return@withLock
this.snapshot = readSnapshot()
val target = movedCursor(current, from, to)
lastPosition = target
windowJob?.cancel()
val fromInWindow = from in windowStart..windowEnd
val toInWindow = to in windowStart..windowEnd
@@ -447,6 +449,7 @@ class PlaybackController(
return@withLock
}
val target = undo.cursor.coerceIn(0, restored.size - 1)
lastPosition = target
val restoredId = queueRepository.itemAt(restored, target)?.song?.id
windowJob?.cancel()
val canMirror =
@@ -951,6 +954,7 @@ class PlaybackController(
} finally {
updating = false
}
lastPosition = target
}
private fun rebuildWindow(