@@ -537,14 +537,16 @@ public final class AppKitBackend: AppBackend {
537537 _ textField: Widget ,
538538 placeholder: String ,
539539 environment: EnvironmentValues ,
540- onChange: @escaping ( String ) -> Void
540+ onChange: @escaping ( String ) -> Void ,
541+ onSubmit: @escaping ( ) -> Void
541542 ) {
542543 let textField = textField as! NSObservableTextField
543544 textField. placeholderString = placeholder
544545 textField. appearance = environment. colorScheme. nsAppearance
545546 textField. onEdit = { textField in
546547 onChange ( textField. stringValue)
547548 }
549+ textField. onSubmit = onSubmit
548550 }
549551
550552 public func getContent( ofTextField textField: Widget ) -> String {
@@ -1055,7 +1057,7 @@ final class NSCustomMenuItem: NSMenuItem {
10551057// than the existing associated keys based approach. And probably more efficient too.
10561058// Source: https://stackoverflow.com/a/36983811
10571059final class Action : NSObject {
1058- private let action : ( ) -> Void
1060+ var action : ( ) -> Void
10591061
10601062 init ( _ action: @escaping ( ) -> Void ) {
10611063 self . action = action
@@ -1197,6 +1199,17 @@ class NSObservableTextField: NSTextField {
11971199 }
11981200
11991201 var onEdit : ( ( NSTextField ) -> Void ) ?
1202+ var _onSubmitAction = Action ( { } )
1203+ var onSubmit : ( ) -> Void {
1204+ get {
1205+ _onSubmitAction. action
1206+ }
1207+ set {
1208+ _onSubmitAction. action = newValue
1209+ action = #selector( _onSubmitAction. run)
1210+ target = _onSubmitAction
1211+ }
1212+ }
12001213}
12011214
12021215// Source: https://gist.github.com/sindresorhus/3580ce9426fff8fafb1677341fca4815
0 commit comments