struct ContentView: View {
   @State private var text: AttributedString = ""
   @State private var selection = AttributedTextSelection()

   var body: some View {
      VStack {
         Button(action: {
            let indices = text.characters.indices
            for index in indices {
               if text.characters[index].isUppercase {
                  let lastIndex = text.characters.index(after: index)
                  text[index..<lastIndex].foregroundColor = .orange
               }
            }
         }, label: {
            Text("Set Characters")
         }).buttonStyle(.glass)

         TextEditor(text: $text, selection: $selection)
            .padding(10)
            .scrollContentBackground(.hidden)
            .background(.gray.opacity(0.2))
            .padding(20)
      }
   }
}