Not quite. We know there is a problem with an Undo that tries to Undo too much. We know how to fix it: we ll just check whether the stack is empty, and if it isn t, we ll do nothing. But we need a test ”let s add one more *undo to the undo.test file:
*enter
*type abc
*output
<P>abc</P>
*end
*undo
*output
<P>ab</P>
*end
*undo
*output
<P>a</P>
*end
*undo
*output
<P></P>
*end
*undo
*output
*end *undo *output *end
This fails, predictably, with the message Stack Empty . Now we can add the feature:
public void Restore() {
if (SavedModels.Count == 0) return;
TextModel savedModel = (TextModel) SavedModels.Pop();
lines = savedModel.Lines;
selectionStart = savedModel.SelectionStart;
}
The tests all run. I believe that functionality is now complete. Let s reflect. In the next chapter ”Chapter 29, The Final Optimized Undo ”we ll turn our attention to efficiency.