mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-05 19:34:18 +00:00
macOS: work on drop destination
This commit is contained in:
@@ -32,8 +32,14 @@ struct TerminalSplitSubtreeView: View {
|
||||
Ghostty.InspectableSurface(
|
||||
surfaceView: leafView,
|
||||
isSplit: !isRoot)
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel("Terminal pane")
|
||||
.dropDestination(for: Ghostty.SurfaceView.self) { views, point in
|
||||
Ghostty.logger.warning("BABY WHAT!")
|
||||
return false
|
||||
} isTargeted: { targeted in
|
||||
Ghostty.logger.warning("BABY TARGETED=\(targeted)")
|
||||
}
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel("Terminal pane")
|
||||
|
||||
case .split(let split):
|
||||
let splitViewDirection: SplitViewDirection = switch (split.direction) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import AppKit
|
||||
import CoreTransferable
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
@@ -6,12 +7,40 @@ extension Ghostty.SurfaceView: Transferable {
|
||||
DataRepresentation(contentType: .ghosttySurfaceId) { surface in
|
||||
withUnsafeBytes(of: surface.id.uuid) { Data($0) }
|
||||
} importing: { data in
|
||||
throw TransferError.importNotSupported
|
||||
guard data.count == 16 else {
|
||||
throw TransferError.invalidData
|
||||
}
|
||||
|
||||
let uuid = data.withUnsafeBytes {
|
||||
$0.load(as: UUID.self)
|
||||
}
|
||||
|
||||
guard let imported = await Self.find(uuid: uuid) else {
|
||||
throw TransferError.invalidData
|
||||
}
|
||||
|
||||
return imported
|
||||
}
|
||||
}
|
||||
|
||||
enum TransferError: Error {
|
||||
case importNotSupported
|
||||
case invalidData
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func find(uuid: UUID) -> Self? {
|
||||
for window in NSApp.windows {
|
||||
guard let controller = window.windowController as? BaseTerminalController else {
|
||||
continue
|
||||
}
|
||||
for surface in controller.surfaceTree {
|
||||
if surface.id == uuid {
|
||||
return surface as? Self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user