Implement drag & drop with the locality model
The second half: system drag sessions over phase 1's model, per DRAG-REORDER.md and 04-interactions.md § Drag & drop. - Card faces, lane headers, and trash rows drag as NSItemProvider sessions (two exported UTTypes, JSON payload in flatten order, plain-text titles as the secondary representation) — replacing m4's custom lane-reorder gesture and trash drag-out wholesale; the app-wide DragSession carries the members, the frozen dragged sizes, the live proposal, and the effective operation. - Three drop delegates (lane masonry, strip, window fallback), each accepting both types and routing internally per the single-target-dispatch rule; the cursor is the physical mouse converted to strip space; proposals come from DropSlotMath with hysteresis threaded through, and the lane-strip proposal clamps in front of the shown trash. - Locality picks the default — move within a board, copy across, the badge tracking live; ⌥ forces copy (ignored on within-board lane drags), ⌘ forces move; trash rows restore within their board (positional), copy out across boards by default, ⌘ forcing the true restore-move. - N contiguous shadows with reflow keyed on the proposal; the committed-overlay hold renders the dropped arrangement until the reload echo lands (1.5 s dissolution deadline for refused writes); the re-grounding trio: geometry re-derives per render, proposals re-validate by liveness at release, an emptied drag cancels itself. - Edge autoscroll (ticking driver over DragAutoScrollMath, re-targeting per step), the mouse-up-gated late-event cleanup, and the polling watchdog — the pathfinder's lifecycle traps, ported. - Store: moveLanes and multi-card restoreByDrag join the one-bracket drop commits. 784 unit tests. Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
@@ -425,6 +425,99 @@ struct ReceiveCardsTests {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Within-board lane moves
|
||||
|
||||
/// A three-lane board, so a run of two can land at either end or between the survivors.
|
||||
@MainActor
|
||||
private func makeThreeLaneBoard() throws -> WriterFixture {
|
||||
let fixture = try WriterFixture()
|
||||
try fixture.item("", Item.board)
|
||||
try fixture.item(Ident.lane1, Item.rich(order: "1024", title: "Todo"))
|
||||
try fixture.item(Ident.lane2, Item.rich(order: "2048", title: "Doing"))
|
||||
try fixture.item(Ident.lane3, Item.rich(order: "3072", title: "Done"))
|
||||
return fixture
|
||||
}
|
||||
|
||||
private func laneTitles(_ fixture: WriterFixture) throws -> [String] {
|
||||
try loaded(fixture).lanes.filter { !$0.isDeleted }.compactMap(\.title.value)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Suite("BoardStore ▸ moveLanes")
|
||||
struct MoveLanesTests {
|
||||
|
||||
@Test("A run of lanes lands contiguously at the drop, in board order")
|
||||
func runLandsContiguously() throws {
|
||||
let fixture = try makeThreeLaneBoard()
|
||||
defer { fixture.tearDown() }
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
let untouched = try stat(fixture, Ident.lane2)
|
||||
|
||||
// Todo and Done together, dropped at 0 — "before what is left", which is Doing. The two
|
||||
// arrive adjacent and in board order even though they were not adjacent to begin with.
|
||||
store.moveLanes([lane1, lane3], toIndex: 0)
|
||||
|
||||
#expect(try laneTitles(fixture) == ["Todo", "Done", "Doing"])
|
||||
// Ranks are inserted, never permuted: the lane that did not move was never opened.
|
||||
#expect(try stat(fixture, Ident.lane2) == untouched)
|
||||
#expect(try order(fixture, Ident.lane2) == .valid(2048))
|
||||
#expect(store.banners.oneShots.isEmpty)
|
||||
}
|
||||
|
||||
@Test("A run dropped past the survivors appends in order")
|
||||
func runAppends() throws {
|
||||
let fixture = try makeThreeLaneBoard()
|
||||
defer { fixture.tearDown() }
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
|
||||
store.moveLanes([lane1, lane2], toIndex: 1)
|
||||
|
||||
#expect(try laneTitles(fixture) == ["Done", "Todo", "Doing"])
|
||||
}
|
||||
|
||||
@Test("A single lane behaves exactly as the singular command does")
|
||||
func singleLane() throws {
|
||||
let fixture = try makeThreeLaneBoard()
|
||||
defer { fixture.tearDown() }
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
|
||||
store.moveLanes([lane3], toIndex: 0)
|
||||
|
||||
#expect(try laneTitles(fixture) == ["Done", "Todo", "Doing"])
|
||||
}
|
||||
|
||||
@Test("A drag that lands where everything already is writes nothing")
|
||||
func noOpDropWritesNothing() throws {
|
||||
let fixture = try makeThreeLaneBoard()
|
||||
defer { fixture.tearDown() }
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
let before = try [Ident.lane1, Ident.lane2, Ident.lane3].map { try stat(fixture, $0) }
|
||||
|
||||
store.moveLanes([lane1], toIndex: 0)
|
||||
store.moveLanes([lane1, lane2], toIndex: 0)
|
||||
store.moveLanes([], toIndex: 1)
|
||||
store.moveLanes([ItemID(rawValue: Ident.indexless)], toIndex: 0)
|
||||
|
||||
#expect(try [Ident.lane1, Ident.lane2, Ident.lane3].map { try stat(fixture, $0) } == before)
|
||||
#expect(store.banners.oneShots.isEmpty)
|
||||
}
|
||||
|
||||
@Test("An out-of-range index clamps rather than trapping")
|
||||
func indexClamps() throws {
|
||||
// A store apiece: a write does not touch the snapshot (the one-way flow), so two drops
|
||||
// against one store would both be computed against the pre-drop board.
|
||||
let high = try makeThreeLaneBoard()
|
||||
defer { high.tearDown() }
|
||||
try BoardStore(rootURL: high.root).moveLanes([lane1], toIndex: 99)
|
||||
#expect(try laneTitles(high) == ["Doing", "Done", "Todo"])
|
||||
|
||||
let low = try makeThreeLaneBoard()
|
||||
defer { low.tearDown() }
|
||||
try BoardStore(rootURL: low.root).moveLanes([lane3], toIndex: -5)
|
||||
#expect(try laneTitles(low) == ["Done", "Todo", "Doing"])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Cross-board lane arrivals
|
||||
|
||||
@MainActor
|
||||
@@ -579,6 +672,45 @@ struct RestoreByDragPositionTests {
|
||||
#expect(try titles(lane1, in: fixture) == ["First", "Third", "Trashed"])
|
||||
#expect(try order(fixture, "\(Ident.lane1)/\(Ident.card2)") == .valid(4096))
|
||||
}
|
||||
|
||||
@Test("A multi-row restore lands the run contiguously, in drop order, in one bracket")
|
||||
func multiRestore() throws {
|
||||
let fixture = try WriterFixture()
|
||||
defer { fixture.tearDown() }
|
||||
try fixture.item("", Item.board)
|
||||
try fixture.item(Ident.lane1, Item.rich(order: "1024", title: "Todo"))
|
||||
try fixture.item("\(Ident.lane1)/\(Ident.card1)", Item.rich(order: "1024", title: "First"))
|
||||
try fixture.item("\(Ident.lane1)/\(Ident.card2)", tombstoned(order: "2048", title: "TrashedA"))
|
||||
try fixture.item("\(Ident.lane1)/\(Ident.card3)", tombstoned(order: "3072", title: "TrashedB"))
|
||||
try fixture.item(Ident.lane2, Item.rich(order: "2048", title: "Doing"))
|
||||
try fixture.item("\(Ident.lane2)/\(Ident.card4)", Item.rich(order: "1024", title: "Fourth"))
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
|
||||
store.restoreByDrag(cardIDs: [card3, card2], intoLane: lane2, at: 0)
|
||||
|
||||
#expect(try titles(lane2, in: fixture) == ["TrashedB", "TrashedA", "Fourth"],
|
||||
"the payload's order is the landing order")
|
||||
#expect(TrashModel.isEmpty(try loaded(fixture)))
|
||||
#expect(!fixture.exists("\(Ident.lane1)/\(Ident.card2)"))
|
||||
#expect(!fixture.exists("\(Ident.lane1)/\(Ident.card3)"))
|
||||
#expect(store.banners.oneShots.isEmpty)
|
||||
}
|
||||
|
||||
@Test("A row that is not a trash row is skipped, and an empty list writes nothing")
|
||||
func skipsWhatIsNotARow() throws {
|
||||
let fixture = try makeTrashBoard()
|
||||
defer { fixture.tearDown() }
|
||||
let store = try BoardStore(rootURL: fixture.root)
|
||||
let untouched = try stat(fixture, "\(Ident.lane1)/\(Ident.card1)")
|
||||
|
||||
// `card1` is live — it has no trash row to drag — and `indexless` names nothing.
|
||||
store.restoreByDrag(cardIDs: [card1, ItemID(rawValue: Ident.indexless)], intoLane: lane2, at: 0)
|
||||
store.restoreByDrag(cardIDs: [], intoLane: lane2, at: 0)
|
||||
|
||||
#expect(try titles(lane2, in: fixture) == ["Fourth"])
|
||||
#expect(try stat(fixture, "\(Ident.lane1)/\(Ident.card1)") == untouched)
|
||||
#expect(store.banners.oneShots.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
Reference in New Issue
Block a user