0

Are there simple ways to insert a character (arrow) not at the end of the string, but where the cursor is currently located? How can I do that?

import SwiftUI

struct ContentView: View {

@State var text = ""

var body: some View {
    
    VStack(spacing: 20) {
        
        TextEditor(text: $text)
            .font(.largeTitle)
    
        Button("➡️"){
            text.append("➡️")
        }
        .font(.largeTitle)
        
    }
    .padding()
}
}
Peter_22
  • 41
  • 5
  • 1
    There's no way to get a cursor position in TextEditor. You can use a wrapper for `UITextField` though. See: https://stackoverflow.com/questions/71367100/how-do-i-get-the-position-of-the-cursor-of-texteditor-in-swiftui – timbre timbre Aug 08 '23 at 19:20

0 Answers0