'How to enable pasting with keyboard shortcut into SwiftUI macOS agent application

I'm creating an app with Swift 5 and SwiftUI. The application runs as a status bar app (LSUIElement is true). I've created a simple preferences window with SwiftUI with a couple of TextField.

However, I don't know how I can enable pasting into those fields with Cmd+V. The app being an agent, it's never really activated so even with the preferences window focused, app's menu bar doesn't show up (on the left-hand side of the status bar).

This is how I create the window:

let hostingController = NSHostingController(rootView: PreferencesView())
preferencesWindow = NSWindow(contentViewController: hostingController)
preferencesWindow!.center()
preferencesWindow!.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

When trying to paste using Cmd+V I hear the macOS's "forbidden" chime. Right-clicking the field allows me to select Paste from the popup menu.



Solution 1:[1]

I have the same trouble, then I find these shortcuts is provided by the 'Edit' menu item. so you can try restoring the default menu in Main.storyboard.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pudge Ma