Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions Muxy/Views/Workspace/TabStrip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ struct PaneTabStrip: View {
}
}
.gesture(
DragGesture(minimumDistance: 4, coordinateSpace: .named(DragCoordinateSpace.mainWindow))
DragGesture(minimumDistance: 0, coordinateSpace: .named(DragCoordinateSpace.mainWindow))
.onChanged { value in
handleDragChanged(
tab: tab,
globalLocation: value.location,
dragStartGlobalLocation: value.startLocation
)
}
.onEnded { _ in
handleDragEnded()
.onEnded { value in
handleDragEnded(
tab: tab,
globalLocation: value.location,
dragStartGlobalLocation: value.startLocation
)
}
)
.onTapGesture {
guard dragState.draggedID == nil else { return }
onSelectTab(tab.id)
}
}
}
}
Expand All @@ -162,12 +162,24 @@ struct PaneTabStrip: View {
DevelopmentBadge()
}

private static let dragActivationDistance: CGFloat = 4

private func handleDragChanged(
tab: TabSnapshot,
globalLocation: CGPoint,
dragStartGlobalLocation: CGPoint
) {
if !dragState.didSelect {
dragState.didSelect = true
onSelectTab(tab.id)
}

let dx = globalLocation.x - dragStartGlobalLocation.x
let dy = globalLocation.y - dragStartGlobalLocation.y
let distance = (dx * dx + dy * dy).squareRoot()

if dragState.draggedID == nil {
guard distance >= Self.dragActivationDistance else { return }
dragState.draggedID = tab.id
dragState.lastReorderTargetID = nil
}
Expand All @@ -177,9 +189,7 @@ struct PaneTabStrip: View {
return
}

let verticalEscape = abs(globalLocation.y - dragStartGlobalLocation.y) > 24

if verticalEscape, !tab.isPinned {
if abs(dy) > 24, !tab.isPinned {
dragState.isInSplitMode = true
dragCoordinator.beginDrag(tabID: tab.id, sourceAreaID: areaID, projectID: projectID)
dragCoordinator.updatePosition(globalLocation)
Expand All @@ -189,7 +199,14 @@ struct PaneTabStrip: View {
reorderIfNeeded(at: globalLocation)
}

private func handleDragEnded() {
private func handleDragEnded(
tab: TabSnapshot,
globalLocation: CGPoint,
dragStartGlobalLocation: CGPoint
) {
if !dragState.didSelect {
onSelectTab(tab.id)
}
if dragState.isInSplitMode {
if let result = dragCoordinator.endDrag() {
onDropAction(result)
Expand All @@ -200,6 +217,7 @@ struct PaneTabStrip: View {
dragState.isInSplitMode = false
dragState.frames = [:]
dragState.lastReorderTargetID = nil
dragState.didSelect = false
}
}

Expand Down Expand Up @@ -235,6 +253,7 @@ private struct TabDragState {
var frames: [UUID: CGRect] = [:]
var isInSplitMode = false
var lastReorderTargetID: UUID?
var didSelect = false
}

private typealias TabFramePreferenceKey = UUIDFramePreferenceKey<TabFrameTag>
Expand Down
Loading