Why Delete has to remember what it deleted
transcript
You delete a word, and press undo. Simple enough. The word comes back. But where was it kept? Think about it for a second.
An insert knows what it added, and where. Undo is a formula. Remove that many characters. A delete can't do that. Once it runs, the text is gone. The document no longer holds it.
So the delete takes a copy as it runs. In execute. Before the text goes. Not in the constructor. It isn't known until the delete runs. Redo is just execute again, so it copies again. Same text, same place.
Uppercase has the same problem. Nothing turns BUY back into Buy. The case is lost. So it keeps the old text, and puts it back.
If a formula can undo it, use one. Insert does exactly that. If not, store what you replaced. Then undo is just putting it back.
Full breakdown in the lecture.