I have an IntentionAction. In the invoke() method I do some code modification, namely something.getModifierList().addAnnotation(aString). This works fine, until I try to create a popup using PopupChooserBuilder and call addAnnotation in the callback. I tried wrapping it in Application.runWriteAction(), which must be called from the event dispatch thread, so I'm wrapping runWriteAction in Application.invokeLater(). This works, but the change cannot be undone, when I click on Undo, I get a message that the last action cannot be undone. This doesn't happen when I don't use the popup and call addAnnotation() directly in my action's invoke() method. How can I make this work correctly?