feat: add extension to normalize OSPasteboard string interface
parent
ed52160612
commit
bf716a0c39
|
|
@ -109,6 +109,7 @@
|
||||||
Helpers/CrossKit.swift,
|
Helpers/CrossKit.swift,
|
||||||
"Helpers/Extensions/NSImage+Extension.swift",
|
"Helpers/Extensions/NSImage+Extension.swift",
|
||||||
"Helpers/Extensions/OSColor+Extension.swift",
|
"Helpers/Extensions/OSColor+Extension.swift",
|
||||||
|
"Helpers/Extensions/OSPasteboard+Extension.swift",
|
||||||
);
|
);
|
||||||
target = 8193244C2F24E6C000A9ED8F /* DockTilePlugin */;
|
target = 8193244C2F24E6C000A9ED8F /* DockTilePlugin */;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ extension Ghostty.OSSurfaceView {
|
||||||
|
|
||||||
init(
|
init(
|
||||||
from startSearch: Ghostty.Action.StartSearch,
|
from startSearch: Ghostty.Action.StartSearch,
|
||||||
pasteboard: OSPasteboard = OSPasteboard(name: .find)
|
pasteboard: OSPasteboard = OSPasteboard.find
|
||||||
) {
|
) {
|
||||||
self.pasteboard = pasteboard
|
self.pasteboard = pasteboard
|
||||||
if let needle = startSearch.needle, !needle.isEmpty {
|
if let needle = startSearch.needle, !needle.isEmpty {
|
||||||
|
|
@ -143,7 +143,7 @@ extension Ghostty.OSSurfaceView {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPasteboardNeedle() {
|
func readPasteboardNeedle() {
|
||||||
let pasteboardNeedle = pasteboard.string(forType: .string)
|
let pasteboardNeedle = pasteboard.string
|
||||||
if let pasteboardNeedle, pasteboardNeedle != needle {
|
if let pasteboardNeedle, pasteboardNeedle != needle {
|
||||||
needle = pasteboardNeedle
|
needle = pasteboardNeedle
|
||||||
needleSelection = needle.startIndex..<needle.endIndex
|
needleSelection = needle.startIndex..<needle.endIndex
|
||||||
|
|
@ -151,8 +151,7 @@ extension Ghostty.OSSurfaceView {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePasteboardNeedle() {
|
func writePasteboardNeedle() {
|
||||||
pasteboard.clearContents()
|
pasteboard.string = needle
|
||||||
pasteboard.setString(needle, forType: .string)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
typealias StartSearch = Ghostty.Action.StartSearch
|
||||||
|
|
||||||
/// A unique pasteboard for each test case prevents flakiness.
|
/// A unique pasteboard for each test case prevents flakiness.
|
||||||
let pasteboard = OSPasteboard(
|
let pasteboard = OSPasteboard.withUniqueName()
|
||||||
name: OSPasteboard.Name(rawValue: UUID().uuidString)
|
|
||||||
)
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
pasteboard.setString("pb", forType: .string)
|
pasteboard.setString("pb", forType: .string)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue