Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ enum GhosttyPasteboardHelper {
return hasPasteableContents(in: pasteboard)
}

static func fallbackPlainTextContents(from pasteboard: NSPasteboard) -> String? {
plainTextContents(from: pasteboard)
}

static func writeString(_ string: String, to location: ghostty_clipboard_e) {
guard let pasteboard = pasteboard(for: location) else { return }
pasteboard.clearContents()
Expand Down
5 changes: 5 additions & 0 deletions Sources/TerminalImageTransfer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ enum TerminalImageTransferPlanner {
return .fileURLs([imageURL])
}

// Clipboard managers can advertise unusable image types alongside valid text.
if let string = GhosttyPasteboardHelper.fallbackPlainTextContents(from: pasteboard), !string.isEmpty {
return .insertText(string)
}

if let rawURL = pasteboard.string(forType: .URL), !rawURL.isEmpty {
return .insertText(escapeForShell(rawURL))
}
Expand Down
18 changes: 18 additions & 0 deletions cmuxTests/TerminalAndGhosttyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@ final class GhosttyPasteboardHelperTests: XCTestCase {
XCTAssertEqual(targetResolutionCount, 0)
}

func testPastePlanFallsBackToAlternatePlainTextWhenImageTypeIsUnusable() {
let pasteboard = NSPasteboard(name: .init("cmux-test-raycast-fallback-\(UUID().uuidString)"))
pasteboard.clearContents()
pasteboard.setString(
"hello from Raycast",
forType: NSPasteboard.PasteboardType(UTType.plainText.identifier)
)
pasteboard.setData(Data("not a real tiff".utf8), forType: .tiff)

let plan = TerminalImageTransferPlanner.plan(
pasteboard: pasteboard,
mode: .paste,
target: .local
)

XCTAssertEqual(plan, .insertText("hello from Raycast"))
}

func testLazyPastePlanResolvesTargetForFileURLPaste() throws {
let fileURL = FileManager.default.temporaryDirectory.appendingPathComponent("clipboard-image-\(UUID().uuidString).png")
try make1x1PNG(color: .systemTeal).write(to: fileURL)
Expand Down
Loading