So, just some context, I have implemented a wrapping SwiftUI View for a NSTextView, everything is working more or less fine, but I would like to add a listener for when the Cmd + Enter combo is pressed, so far I got this:
class Coordinator: NSObject, NSTextViewDelegate {
var parent: NSTextViewWrapper
init(_ parent: NSTextViewWrapper) {
self.parent = parent
}
func textView(_ textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
if commandSelector == #selector(NSResponder.insertNewLine(_:)) {
let event = NSApp.currentEvent
// if event?.modifierFlags != NSEvent.ModifierFlags.command {
// Here I would like to trigger some action when the user is done editing the text field and wants to commit the result
// return true
// }
return false
}
return false
}
For the life of me I cannot figure out how to do this.