Reputation: 421
I used the UndoManager to add undo and redo functionality to my JTextPane. However, it saves the text every time text is entered, so it undos to the last letter. How can I make it undo to the last word?
Upvotes: 2
Views: 2468
Reputation: 57381
http://java-sl.com/tip_merge_undo_edits.html That's an example of such merging edits.
Upvotes: 3
Reputation: 24192
Use UndoableEdit#addEdit()
. If you make non-whitespace edits stick together on the undo stack (by absorbing each other through this method) and whitespace edits too, then the next undo will act on the last work or last whitespace gap, which is what you want.
Upvotes: 2