Should I just add to the undo buffer on all keyevents or what?
Well keyevents might not do you as much good, as you're likely to want to undo changes to the text, not the actual keypresses.There a design pattern called the "Command Pattern" which, amougst other things, solves the undo problem rather elegantly.