fix: keep playlist reordering active while dragging
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import CoreGraphics
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
@@ -10,7 +11,45 @@ struct PlaybackQueueChecks {
|
||||
URL(fileURLWithPath: "/queue-check/" + name + ".mp4")
|
||||
}
|
||||
|
||||
static func dragReordering() {
|
||||
// Unequal heights catch snapping to a row's old center instead of the vacated slot.
|
||||
let frames = [
|
||||
CGRect(x: 0, y: 52, width: 260, height: 60),
|
||||
CGRect(x: 0, y: 112, width: 260, height: 80),
|
||||
CGRect(x: 0, y: 192, width: 260, height: 60),
|
||||
]
|
||||
var queue = PlaybackQueue()
|
||||
queue.replace([file("A"), file("B"), file("C")])
|
||||
let current = queue.currentID
|
||||
var drag = PlaybackQueueDrag(source: 0, frames: frames, scrollOffset: 0)
|
||||
drag.update(translation: 39, scrollOffset: 0)
|
||||
require(drag.destination == 0, "release before the nearest-slot midpoint keeps the original position")
|
||||
drag.update(translation: 41, scrollOffset: 0)
|
||||
require(drag.destination == 1 && drag.offset(at: 1) == -60 && drag.offset(at: 2) == 0,
|
||||
"crossing the midpoint slides only the displaced neighbor")
|
||||
drag.update(translation: 140, scrollOffset: 0)
|
||||
require(drag.destination == 2 && drag.offset(at: 0) == 140,
|
||||
"dragged row follows the pointer continuously to the final slot")
|
||||
// No further pointer update: release consumes the retained gesture state.
|
||||
queue.move(fromOffsets: IndexSet(integer: drag.source), toOffset: drag.insertionOffset)
|
||||
require(queue.items.map(\.url) == [file("B"), file("C"), file("A")] && queue.currentID == current,
|
||||
"stationary release commits the nearest slot without changing playback identity")
|
||||
|
||||
drag = PlaybackQueueDrag(source: 2, frames: frames, scrollOffset: 100)
|
||||
drag.update(translation: -20, scrollOffset: 0)
|
||||
require(drag.destination == 0 && drag.offset(at: 0) == 60 && drag.offset(at: 1) == 60,
|
||||
"scrolling under a stationary pointer moves the row and shifts earlier neighbors down")
|
||||
drag.update(translation: 0, scrollOffset: 100)
|
||||
require(drag.destination == 2 && drag.offset(at: 1) == 0,
|
||||
"reversing a drag restores the original gap")
|
||||
drag.update(translation: -1_000, scrollOffset: 100)
|
||||
require(drag.destination == 0 && drag.insertionOffset == 0, "release above the list selects the first slot")
|
||||
drag.update(translation: 1_000, scrollOffset: 100)
|
||||
require(drag.destination == 2 && drag.insertionOffset == 2, "release below the list selects the last slot")
|
||||
}
|
||||
|
||||
static func main() {
|
||||
dragReordering()
|
||||
let first = file("Episode1"), second = file("Episode2"), tenth = file("Episode10")
|
||||
var queue = PlaybackQueue()
|
||||
require(queue.items.isEmpty && queue.currentURL == nil && !queue.canPrevious && !queue.canNext,
|
||||
|
||||
Reference in New Issue
Block a user