Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On MacOS/SwiftUI how do you use keyboard to submit? #36

Closed
ismyhc opened this issue Feb 9, 2023 · 2 comments
Closed

On MacOS/SwiftUI how do you use keyboard to submit? #36

ismyhc opened this issue Feb 9, 2023 · 2 comments
Labels
discussion Discussions not yet turned into an action

Comments

@ismyhc
Copy link

ismyhc commented Feb 9, 2023

On macOS Is there a simple way to allow "enter" key to submit on RichTextEditor ? I actually couldn't find this feature on the SwiftUI TextEditor either.

I want standard text input for a chat view. Enter submits text, shift+enter adds new line.

Any insight, much appreciated!

@danielsaidi
Copy link
Owner

Hmmm not sure, SwiftUI has a native onSubmit view modifier, but that will (most probably) not work here. Let's keep this open and discuss it further.

@danielsaidi danielsaidi added the feature New feature or request label Feb 10, 2023
@danielsaidi
Copy link
Owner

@ismyhc I have verified that you can use the SwiftUI .onKeyPress(.return) modifier, for instance:

RichTextEditor(
    text: $document.text,
    context: context
)
.onKeyPress(.return) {
    print("Save")
    return .handled
}

Keep in mind that if you do this, the text field will not insert any new lines.

Also, if you create a document-based app, you have other shortcuts for this action. See the new demo for more info.

@danielsaidi danielsaidi added discussion Discussions not yet turned into an action and removed feature New feature or request labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussions not yet turned into an action
Projects
None yet
Development

No branches or pull requests

2 participants