macos: use preference key to detect self dragging

This commit is contained in:
Mitchell Hashimoto
2025-12-28 13:31:10 -08:00
parent 5245757875
commit 9b7124cf62
2 changed files with 17 additions and 1 deletions

View File

@@ -92,6 +92,7 @@ fileprivate struct TerminalSplitLeaf: View {
let action: (TerminalSplitOperation) -> Void
@State private var dropState: DropState = .idle
@State private var isSelfDragging: Bool = false
var body: some View {
GeometryReader { geometry in
@@ -105,11 +106,15 @@ fileprivate struct TerminalSplitLeaf: View {
action: action
))
.overlay {
if case .dropping(let zone) = dropState {
if !isSelfDragging, case .dropping(let zone) = dropState {
zone.overlay(in: geometry)
.allowsHitTesting(false)
}
}
.onPreferenceChange(Ghostty.DraggingSurfaceKey.self) { value in
Ghostty.logger.warning("BABY WE DRAGGING \(String(describing: value))")
isSelfDragging = value == surfaceView.id
}
.accessibilityElement(children: .contain)
.accessibilityLabel("Terminal pane")
}

View File

@@ -1,6 +1,16 @@
import SwiftUI
extension Ghostty {
/// A preference key that propagates the ID of the SurfaceView currently being dragged,
/// or nil if no surface is being dragged.
struct DraggingSurfaceKey: PreferenceKey {
static var defaultValue: SurfaceView.ID? = nil
static func reduce(value: inout SurfaceView.ID?, nextValue: () -> SurfaceView.ID?) {
value = nextValue() ?? value
}
}
/// A grab handle overlay at the top of the surface for dragging the window.
/// Only appears when hovering in the top region of the surface.
struct SurfaceGrabHandle: View {
@@ -38,6 +48,7 @@ extension Ghostty {
.draggable(surfaceView) {
SurfaceDragPreview(surfaceView: surfaceView, scale: previewScale)
}
.preference(key: DraggingSurfaceKey.self, value: isDragging ? surfaceView.id : nil)
}
}