Skip to content

Instantly share code, notes, and snippets.

@rcarver
Created March 19, 2026 04:47
Show Gist options
  • Select an option

  • Save rcarver/a9c8160ae7a38777e92486c5c7959816 to your computer and use it in GitHub Desktop.

Select an option

Save rcarver/a9c8160ae7a38777e92486c5c7959816 to your computer and use it in GitHub Desktop.
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