Undo/Redo on TextArea (need ideas)
921640Apr 30 2012 — edited Jun 14 2012This is not strictly a JavaFX 2 question, but we have some darn good programmers here, so I know you guys can help me.
Namely, I would like to implement a Undo/Redo function for my application, and I'm having trouble with TextInput controls. This is my system: have two Stacks (undoStack and redoStack) in which I store my undo/redo VALUES. Basically, every time a control's value changes I collect all of the object's properties values (state) and store it in the appropriate stack. This is done via ChangeListeners. It's a little bit cumbersome because I have to add a ChangeListener to each and every control on the form and store all of the object's values if only one of them changes. But, I'm OK with that.
The trouble is, since I'm storing values onChange, the program pushes one value into the undoStack every time the user presses a keyboard key. So for the text "Hello world!" it would be *12* undoStack items. I don't want that. What I would like to implement is the text-editors-like behavior. That is, to undo/redo several words (or a sentence) at once, plus cut/copy/paste and similar operations. Any ideas or guidelines?