Undo and redo only earn trust when they compose across a real sequence of edits. Today you drive a mixed session and step backward and forward through it.
Run a sequence of edits and confirm undo and redo walk through the history correctly.
This session ties the whole chapter together. Typing "abc" is one coalesced group;
Enter is its own; typing "xyz" is a third. So the history has exactly three steps,
and undo walks them in reverse: the first undo peels off the "xyz" run and puts the
cursor back at the start of the new line, the second undoes the Enter and drops you
to the end of "abc". Each step restores the cursor along with the text, so you are
returned to precisely where each edit began.
Redo then retraces the path forward, re-applying the Enter and landing you back at
"abc\n" with the cursor where it belonged. The coalescing, the two stacks, and the
cursor-carrying snapshots all show their work at once here, exactly as they will when
a person hammers undo and redo in a real edit. With the model proven end to end
through its history, only one thing is left: to run the entire editor from a single
scripted session - open, edit, search, save - and check it lands precisely where the
design says it should.
for _, c := range "abc" { e.InsertChar(c) } // undo group 1e.Enter() // undo group 2for _, c := range "xyz" { e.InsertChar(c) } // undo group 3e.Undo(); e.Undo(); e.Redo()// assert Text() and cursor at each step