mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-27 15:25:19 +00:00
feat: add extension to normalize OSPasteboard string interface
This commit is contained in:
@@ -109,6 +109,7 @@
|
||||
Helpers/CrossKit.swift,
|
||||
"Helpers/Extensions/NSImage+Extension.swift",
|
||||
"Helpers/Extensions/OSColor+Extension.swift",
|
||||
"Helpers/Extensions/OSPasteboard+Extension.swift",
|
||||
);
|
||||
target = 8193244C2F24E6C000A9ED8F /* DockTilePlugin */;
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ extension Ghostty.OSSurfaceView {
|
||||
|
||||
init(
|
||||
from startSearch: Ghostty.Action.StartSearch,
|
||||
pasteboard: OSPasteboard = OSPasteboard(name: .find)
|
||||
pasteboard: OSPasteboard = OSPasteboard.find
|
||||
) {
|
||||
self.pasteboard = pasteboard
|
||||
if let needle = startSearch.needle, !needle.isEmpty {
|
||||
@@ -143,7 +143,7 @@ extension Ghostty.OSSurfaceView {
|
||||
}
|
||||
|
||||
func readPasteboardNeedle() {
|
||||
let pasteboardNeedle = pasteboard.string(forType: .string)
|
||||
let pasteboardNeedle = pasteboard.string
|
||||
if let pasteboardNeedle, pasteboardNeedle != needle {
|
||||
needle = pasteboardNeedle
|
||||
needleSelection = needle.startIndex..<needle.endIndex
|
||||
@@ -151,8 +151,7 @@ extension Ghostty.OSSurfaceView {
|
||||
}
|
||||
|
||||
func writePasteboardNeedle() {
|
||||
pasteboard.clearContents()
|
||||
pasteboard.setString(needle, forType: .string)
|
||||
pasteboard.string = needle
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#if canImport(AppKit)
|
||||
|
||||
/// Normalizes the interface between NSPasteboard and UIPasteboard for working with pasteboard
|
||||
/// strings.
|
||||
extension OSPasteboard {
|
||||
@MainActor static let find = OSPasteboard(name: .find)
|
||||
|
||||
/// The pasteboard's current string value.
|
||||
@MainActor var string: String? {
|
||||
get {
|
||||
string(forType: .string)
|
||||
}
|
||||
set {
|
||||
clearContents()
|
||||
if let newValue {
|
||||
setString(newValue, forType: .string)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elseif canImport(UIKit)
|
||||
|
||||
extension OSPasteboard {
|
||||
static let find = OSPasteboard.withUniqueName()
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,9 +8,7 @@ import Testing
|
||||
typealias StartSearch = Ghostty.Action.StartSearch
|
||||
|
||||
/// A unique pasteboard for each test case prevents flakiness.
|
||||
let pasteboard = OSPasteboard(
|
||||
name: OSPasteboard.Name(rawValue: UUID().uuidString)
|
||||
)
|
||||
let pasteboard = OSPasteboard.withUniqueName()
|
||||
|
||||
init() {
|
||||
pasteboard.setString("pb", forType: .string)
|
||||
|
||||
Reference in New Issue
Block a user