Jutanium
Jutanium

Reputation: 421

JTextPane undo and redo whole words

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

Answers (2)

StanislavL
StanislavL

Reputation: 57381

http://java-sl.com/tip_merge_undo_edits.html That's an example of such merging edits.

Upvotes: 3

radai
radai

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

Related Questions