title: NSTextField edit coalescing
body: <p>I am writing a Cocoa app which contains several NSTextFields. I am trying to propagate changes to the text in the text field to my model layer, but since I am registering an Undo action when the model is updated, this makes it a bit more complicated than simply listening for <code>controlTextDidChange:</code>.</p>
  
  <p>If I hook onto the delegate method <code>controlTextDidChange:</code>, then it gets called once for every key pressed. If I update the model then, the model will treat each separate keypress as a separate Undo event. This is not desirable. What I want is to be notified when the default "Undo Typing" action is registered with the Undo manager, so I can update the model then. The NSTextField registers one (and only one) such event, when I pause typing for a moment. Unfortunately, I have no idea when this occurs.</p>
  
  <p>I have tried listening for <code>controlTextDidEndEditing:</code>, and updating the model in that delegate method, but then I have to explicitly tab out of the text field before the model will update. Since I archive my model object directly in my <code>NSDocument</code> subclass, doing this will result in data loss for the user if they save the document after changing the contents of the text field, but don't tab out of the text field first, because the model would not have been updated in time. Therefore, this technique will not work.</p>
  
  <p>I have also tried hooking onto the text field's field editor (during <code>control:textShouldBeginEditing:</code>) and listening for <code>textDidEndEditing:</code>, but then I find that this simply doesn't fire, so the model won't be updated, causing data loss as described in the previous paragraph. Can anyone help me figure this out? Thanks!</p>