For TextEditor, how do I ignore Shift+Return and only send on Return

25 Views Asked by At

How can I handle sending an event when the return key is pressed and NOT when the return+shift keys are pressed? This would be w/ the TextEditor swiftui component

1

There are 1 best solutions below

0
Tim Nuwin On BEST ANSWER
    TextEditor().onKeyPress { press in
       if (press.key == KeyEquivalent.return && !press.modifiers.contains(EventModifiers.shift)) {
           viewStore.send(.sendMyMessage)
           return .handled
       }
       return .ignored // don't forget to set .ignore otherwise no other keys will appear
    }