Created
March 19, 2026 04:47
-
-
Save rcarver/a9c8160ae7a38777e92486c5c7959816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import AppKit | |
| import SwiftUI | |
| struct ContentView: View { | |
| var body: some View { | |
| VStack { | |
| Text("Click me, then Select All works") | |
| } | |
| .overlay(SelectAllReceiver()) | |
| .padding() | |
| } | |
| } | |
| struct SelectAllReceiver: NSViewRepresentable { | |
| func makeNSView(context: Context) -> CustomView { | |
| CustomView() | |
| } | |
| func updateNSView(_ nsView: CustomView, context: Context) { | |
| } | |
| final class CustomView: NSView, NSMenuItemValidation { | |
| override var acceptsFirstResponder: Bool { | |
| return true | |
| } | |
| func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { | |
| menuItem.action == #selector(selectAll(_:)) | |
| } | |
| override func selectAll(_ sender: Any?) { | |
| print("SELECT ALL") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment