struct ContentView: View {
   @State private var text: AttributedString = ""
   @State private var selection = AttributedTextSelection()
   @Environment(\.fontResolutionContext) var context

   var body: some View {
      VStack {
         Button(action: {
            text.transformAttributes(in: &selection) { container in
               let font = container.font ?? .body
               let bold = font.resolve(in: context).isBold
               
               if bold {
                  container.font = font.bold(false)
               } else {
                  container.font = font.bold(true)
               }
            }
         }, label: {
            Image(systemName: "bold")
         }).buttonStyle(.glass)
         
         TextEditor(text: $text, selection: $selection)
            .padding(10)
            .scrollContentBackground(.hidden)
            .background(.gray.opacity(0.2))
            .padding(20)
      }
   }
}