Text Editor Undo
Last published: June 24, 2010 by 'stevek'
Defines 1 Classes
Extends 4 Classes
This package adds multiple undo and redo levels to TextEditorController. This package is public domain, original implementation was written by Andre Schnoor (see revision 0.1 comment in public repository). Tested with VW 7.4-7.7.
It probably makes sense to add a key for Redo; Ctrl+Y seems common, but does mean you need to remap UserInterrupt to something else (e.g. with "InputState interruptKeyValue: #F8"). To add Ctrl+Y as redo, add it after the #undoKey: binding in UIFeelPolicy>>keyboardDispatchTable (it will only affect windows opened after the change):
The implementation follows a simple, yet effective approach. There is no sophisticated notion of different edit actions or the like. Before a change is applied to the text, a copy of the current text is saved to an undo stack, along with the current selection indexes. These are simply restored upon "undo". Even larger texts should not impose problems, given today's average memory and CPU resources. A series of continous character typing is treated as a single block of action, i.e. "undo" will restore the state prior to when typing started. This saves room on the stack (and memory footprint) and pretty well suits practical needs. The default number of undo levels is 64 (may be changed in TextEditorController>>undoLevels).