2

First time using TextEditor in a macOS project.

According to this:
https://www.hackingwithswift.com/quick-start/swiftui/how-to-let-users-find-and-replace-text
my code should give me built-in Search / Search& Replace, but when I run and hit cmd-F, all I hear is the system "Tok" sound and do nothing.

struct ContentView: View {
    @State var text = "blah blach blach"

    var body: some View {
        NavigationStack {
            TextEditor(text: $text)
                .navigationTitle("Edit Bio")
        }
    }
}

Am I missing something? Already tried this on Apple Silicon and Intel Macs both running Sonoma, same result and building on Xcode 15.3.

1 Answer 1

3

The article you linked talks about iOS, where find & replace is indeed built into TextEditor without needing any extra code.

On macOS, you can add TextEditingCommands to your scene to enable this:

@main
struct FooApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .commands {
            TextEditingCommands()
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.