swiftuitext-editor

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


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


Solution

  •     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
        }