Undo Redo problem for JTextPane
843804Jun 17 2005 — edited Mar 21 2007I'm trying to build a Editor based on JTextPane that has syntax highlighting, indentation, etc. It's like an IDE without actually doing compilation or debugging. I'm working on undo/redo when I run into this problem. Basically, my document extends DefaultStyledDocument and override the insertString method. Now, whenever user inserts a segment of text, i update my parser and ask my parser what color I should set the segment of text to. When i get the appropriate color, I call setCharacterAttribute() to set the color. For undo/redo, this has generated two UndoEvents. One as an INSERT documentEvent and the other as a CHANGE documentEvent for the color change. Therefore, for my UndoableEditListener, it receives two events. Now, when the user press undo, originally it was undoing the color change, then the insert change. This is not what I want. I want it as a single undo action. Any suggestions on how I should go about this?