From 81532c0b5696b75c93e448f289b97260d40dd9d1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 21 Jan 2024 17:26:41 -0800 Subject: [PATCH] macos: support reading service result text into terminal --- macos/Sources/Ghostty/SurfaceView_AppKit.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 8663c922a..251ddeaa8 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -998,7 +998,15 @@ extension Ghostty.SurfaceView: NSServicesMenuRequestor { } func readSelection(from pboard: NSPasteboard) -> Bool { - // TODO - return false + guard let str = pboard.string(forType: .string) else { return false } + + let len = str.utf8CString.count + if (len == 0) { return true } + str.withCString { ptr in + // len includes the null terminator so we do len - 1 + ghostty_surface_text(surface, ptr, UInt(len - 1)) + } + + return true } }