title: Detect when a user stopped typing on a TextEditor in SwiftUI (macOS)
body: <p>I'm saving the text of a <code>TextEditor</code> to a text file. I start by creating the file with the first line of the <code>TextEditor</code> as the filename, and then subsequent updates are saved on that file. The code lives on a <code>.onChange</code> action. This presents a challenge since I'm creating a file for each character the use type on the first line of the <code>TextEditor</code>.</p>
  <p>Is there a way to detect when the user stopped typing, or the component is idle, and then create the file and save the text? This is on macOS Big Sur.</p>
  <p>I haven't been able to find any action I can use. Code follows for the view:</p>
  <pre><code>    @EnvironmentObject private var data: DataModel
      var note: NoteItem        
      @State var text: String
      
      var body: some View {
          HStack {
              VStack(alignment: .leading) {
                  TextEditor(text: $text)
                      //.onTapGesture {
                      // tried with this....
                      //    print(&quot;stopped typing&quot;)
                      //}
                      .onChange(of: text, perform: { value in
                          guard let index = data.notes.firstIndex(of: note) else { return }
                          data.notes[index].text = value
                          data.notes[index].date = Date()
                          data.notes[index].filename = value.components(separatedBy: NSCharacterSet.newlines).first!
                          saveFile(filename: data.notes[index].filename, contents: data.notes[index].text)
                      })                    
              }
          }
  </code></pre>