Fix dragging an existing pedal into a region lane (cross-lane move)
Drag/drop only supported add: (palette→anywhere) and same-lane reorders, so dragging a pedal from the main chain (or another lane) into a Stereo Unzip / Split / Parallel lane highlighted the lane but the drop was a no-op. - New core ShoeGaze.movePedal(from:at:to:in:) moves a pedal across lanes, preserving its PedalState (params), with destination-index correction when the removal deletes a top-level segment before the target region. - BoardFlowView routes movemain:/movebranch: payloads dropped on a lane (or the main chain, or another lane's card) through it via moveAcross(_:toLane:). Tests: move a main pedal into an unzip lane (params preserved); move a pedal that sits before the region (index-adjust path). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -400,16 +400,19 @@ public struct BoardFlowView: View {
|
||||
reorderMain(from: src, onto: ontoLinear)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
// A branch pedal dragged back onto the main chain → cross-lane move.
|
||||
return moveAcross(payload, toLane: .main)
|
||||
}
|
||||
|
||||
private func handleLaneDrop(_ items: [String], lane: PedalLane) -> Bool {
|
||||
dropTarget = nil
|
||||
guard let payload: String = parse(items), let type: String = payload.afterPrefix("add:") else {
|
||||
return false
|
||||
guard let payload: String = parse(items) else { return false }
|
||||
if let type: String = payload.afterPrefix("add:") {
|
||||
append(type: type, lane: lane)
|
||||
return true
|
||||
}
|
||||
append(type: type, lane: lane)
|
||||
return true
|
||||
// A pedal from the main chain or another lane dragged into this lane → cross-lane move.
|
||||
return moveAcross(payload, toLane: lane)
|
||||
}
|
||||
|
||||
private func handleBranchCardDrop(_ items: [String], lane: PedalLane, ontoIndex: Int) -> Bool {
|
||||
@@ -426,7 +429,7 @@ public struct BoardFlowView: View {
|
||||
append(type: type, lane: lane)
|
||||
return true
|
||||
}
|
||||
// Reorder within the same lane only: "movebranch:<region>:<side>:<index>".
|
||||
// Reorder within the same lane: "movebranch:<region>:<side>:<index>".
|
||||
let parts: [Substring] = payload.split(separator: ":")
|
||||
if parts.count == 4, parts[0] == "movebranch",
|
||||
Int(parts[1]) == lane.regionIndex,
|
||||
@@ -435,7 +438,35 @@ public struct BoardFlowView: View {
|
||||
reorderBranch(from: src, onto: ontoIndex, lane: lane)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
// A pedal from the main chain or a different lane dropped onto a card here → cross-lane move.
|
||||
return moveAcross(payload, toLane: lane)
|
||||
}
|
||||
|
||||
/// Moves a pedal addressed by a `movemain:`/`movebranch:` payload into `destination`,
|
||||
/// preserving its parameters. Returns `false` if the payload isn't a recognised move.
|
||||
private func moveAcross(_ payload: String, toLane destination: PedalLane) -> Bool {
|
||||
guard let board: PedalBoard = board else { return false }
|
||||
let sourceLane: PedalLane
|
||||
let sourceIndex: Int
|
||||
if let mainIndex: Int = payload.afterPrefix("movemain:").flatMap(Int.init) {
|
||||
sourceLane = .main
|
||||
sourceIndex = mainIndex
|
||||
} else {
|
||||
let parts: [Substring] = payload.split(separator: ":")
|
||||
guard parts.count == 4, parts[0] == "movebranch",
|
||||
let region: Int = Int(parts[1]), let index: Int = Int(parts[3]) else {
|
||||
return false
|
||||
}
|
||||
sourceLane = (parts[2] == "L") ? .left(region: region) : .right(region: region)
|
||||
sourceIndex = index
|
||||
}
|
||||
do {
|
||||
_ = try shoeGaze.movePedal(from: sourceLane, at: sourceIndex, to: destination, in: board)
|
||||
return true
|
||||
} catch {
|
||||
print("[BoardFlowView] cross-lane move failed: \(error)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Edit actions
|
||||
|
||||
Reference in New Issue
Block a user