~learn.
0:00 / 1:10
LLD · Text Editor

Ctrl+Z took the word, not the letter. Here's the rule.

transcript

Type Hello world. Press control Z. World disappears. Not the d. Not the whole line. The word.

Each keystroke is a command. H starts a group. E, l, l, o and the space are quick and adjacent. Absorbed. Then w. The group ends in a space, so it's a new word. Two undo steps: Hello with its space, then world.

A group keeps swallowing keystrokes until something ends it. A cursor move. A pause of more than a second. A new word. And a paste is always its own step.

Without grouping, a 40-character sentence leaves 40 undo steps. With it, one undo takes a word. Three quick backspaces? One undo brings all three back.

But here's the catch. Undo, then type something new. Redo is cleared. Those steps point at text that no longer exists.

Keystrokes merge while adjacent, quick, and inside one word. One undo, one word. That's what feels like a real editor.

Full breakdown in the lecture.