File tree Expand file tree Collapse file tree 5 files changed +17
-11
lines changed
Modules/Sources/AppKitExtensions/Foundation Expand file tree Collapse file tree 5 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 1414 if: github.event.pull_request.draft == false
1515 env:
1616 node-version: '20.x'
17- DEVELOPER_DIR: /Applications/Xcode_16.2 .app/Contents/Developer
17+ DEVELOPER_DIR: /Applications/Xcode_16.3 .app/Contents/Developer
1818
1919 defaults:
2020 run:
Original file line number Diff line number Diff line change 77import AppKit
88
99public extension NSPasteboard {
10- var canPaste : Bool {
11- pasteboardItems?.isEmpty == false
10+ var hasText : Bool {
11+ pasteboardItems?.contains { $0.types.contains(.string) } == true
1212 }
1313
1414 var string: String? {
1515 string(forType: .string)
1616 }
1717
18- var url: String? {
19- guard let string else {
20- return string(forType: .URL)
18+ func url() async -> String? {
19+ guard #available(macOS 15.4, *) else {
20+ guard let string else {
21+ return string(forType: .URL)
22+ }
23+
24+ return NSDataDetector.extractURL(from: string)
2125 }
2226
23- return NSDataDetector.extractURL(from: string)
27+ // This alerts the user only when the pasteboard really contains links
28+ let values = try? await NSPasteboard.general.detectedValues(for: [\.links])
29+ return values?.links.first?.url.absoluteString
2430 }
2531
2632 func overwrite(string: String?) {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ extension EditorViewController {
2222 // Try our best to guess from selection and clipboard
2323 bridge.format.insertHyperLink(
2424 title: prefersURL ? defaultTitle : title,
25- url: prefersURL ? text : (NSPasteboard.general.url ?? "https://"),
25+ url: prefersURL ? text : (await NSPasteboard.general.url() ?? "https://"),
2626 prefix: prefix
2727 )
2828 }
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ private extension EditorWebView {
134134
135135 // Disable paste for empty pasteboard
136136 if item.tag == WKContextMenuItemTag.paste.rawValue {
137- item.isEnabled = NSPasteboard.general.canPaste
137+ item.isEnabled = NSPasteboard.general.hasText
138138 }
139139
140140 // Hide native items that require text selection
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ private extension AppDelegate {
3939 $0?.superMenuItem?.isHidden = document?.fileURL == nil
4040 }
4141
42- fileFromClipboardItem?.isHidden = !NSPasteboard.general.canPaste
42+ fileFromClipboardItem?.isHidden = !NSPasteboard.general.hasText
4343 }
4444
4545 func reconfigureMainEditMenu(document: EditorDocument?) {
@@ -50,7 +50,7 @@ private extension AppDelegate {
5050
5151 editUndoItem?.isEnabled = await document.canUndo
5252 editRedoItem?.isEnabled = await document.canRedo
53- editPasteItem?.isEnabled = NSPasteboard.general.canPaste
53+ editPasteItem?.isEnabled = NSPasteboard.general.hasText
5454 }
5555
5656 // [macOS 15] The system one doesn't work for WKWebView
You can’t perform that action at this time.
0 commit comments