Aa 0.14.1

Undo

Undo takes back a word, not a letter, and puts the caret where the change it took back was.

Steps to undo

Type a sentence, delete a word, press Enter and bold a word. Then press ⌘Z a few times, and ⌘⇧Z to go forward again.

What it stores

Undo is a stack of whole documents, which are small. What makes a step:

ChangeStep
Letters typed one after another, in the same block, within a momentOne step: the word.
A space after a wordBegins a new step.
Letters deleted one after anotherOne step, apart from the typing before it.
Enter, Backspace across a block’s edge, paste, cut, a mark, a linkA step of its own.
A command from a menu, with the / and the letters typed for itOne step.
Moving, duplicating or deleting blocks, by hand or from the keysA step of its own.
A correction made while writingA step of its own. See Correction while writing.
An AI answer, everything it changedOne step. See Asking AI.
Find’s Replace allOne step.

A moment is 700 milliseconds: letters typed with a longer pause between them are a step apart.

Undo puts the caret at the end of the change it took back, not where the caret stood after the step before, so the next keys go on where the change was. Redo goes forward to the step undone, with the caret where it was after that step. Either way the page scrolls just far enough to show the caret, and not at all while it is in view.

KeyWhat it does
⌘ZUndo.
⌘⇧ZRedo.
⌘YRedo.

On Windows and Linux, Control takes the place of ⌘. The browser’s own Undo and Redo, from its Edit menu, go through the same steps. A read-only editor neither undoes nor redoes.

editor.undo()          // false when there is nothing to undoeditor.redo()editor.transaction(() => {  editor.replace(0, 0, '# Minutes\n\n')  editor.replace(editor.value.length, editor.value.length, '\n\nNext meeting: Monday.')})                     // both changes, one step

replace() is one step on its own. Setting value from outside starts the steps afresh: what came before it cannot be undone. With shared editing, undo is Yjs’s own, through setHistoryProvider, and takes back only the person’s own changes, never another’s.

Selecting and moving · Keyboard · Methods and events