VisualEditor/Undo and Redo

Undo
Intuitively, undoes the last thing you did. Does not undo, for instance, a user-initiated deletion & insertion. This must be distinguished from a delete/insert sequence that we recorded because that was the simple way to accomplish text that, when pasted, replaced the selection.

Undo never depends on the current selection, only the last action you took.

Redo
Redoes something you just did.

Implementation
The Visual Editor currently has a model of transactions, each of which has a number of operations. Typical single-character insert transaction contains "retain" which locates the cursor, "insert" one character, then "retain" again to go to the end of the document (uncertain what that does for us).

Question, shouldn't insert/delete text be made to be a single transaction, not split among many? Or is it that way already?

These transactions are grouped into "states", which is a bit of a misnomer as they don't describe the state of the editor, they just bundle transactions together.

When recording a transaction, can also add 'combine' flag to indicate it ... (?should be combined) with other transactions in state. For instance, when typing individual characters you want them combined into the same "state" so they will all be undone together.

Original implementation inserted select events into state, which neatly divided bursts of typing. Seemed that we did not need that since we could infer previous selection state from transactions. But now I am starting to see why Trevor added this, it's just easier to keep that history of selections rather than reconstruct it. (?)