Design a text editor with undo and redo
PremiumLow-level designMedium
- Undo redo
- Command pattern
- Memento pattern
Quick answer
This low-level design interview question asks you to design a text editor with undo and redo. Aim for a design that is modelled as clear classes, interfaces and relationships that can handle new requirements without a rewrite. Interviewers want to see how you name responsibilities, keep classes small and reason about change.
The problem
Text editor undo and redo, low level design: build the core under the editor user interface that holds the document, cursor and selection, and applies typing, delete, cut, paste and find and replace. Every edit can be undone and redone. The hard parts are grouping keystrokes and fast edits on 10 MB files.
Consecutive keystrokes are grouped so one undo removes a typed word, not one letter. Undo history must store what changed, not a copy of the document per edit.
What must a text editor with undo and redo do?
- Undo and redo: Undo back to the opening of the file, within the history limit given below. Redo is available until a new edit is made, which clears the redo stack.
- Grouping: Characters typed within 500 ms of each other, without moving the cursor, form one undo step. Replace-all is one step regardless of how many matches it touches.
How well must it do it?
- Fast edits: Inserting a character in the middle of a 10 MB document must not copy the whole document; aim for well under 1 ms per keystroke.
- Bounded memory: Undo history must store what changed, not a copy of the document per edit.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- Undo redo
- Command pattern
- Memento pattern
- Gap buffer
- Piece table
- Text buffers
How you’ll practise
- Requirements
- Core objects
- Class relationships
- Key flows
- Extensibility
- Wrap-up
Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.
What do interviewers look for?
In any low-level design round.
- Lists the use cases before writing classes
- Gives each class one clear responsibility
- Uses interfaces where behaviour is likely to change
- Applies a design pattern only when it solves a real problem
- Handles edge cases and invalid states explicitly
- Walks through one use case end to end with the model
Questions people ask about this interview question
- Which design type is this question?
- It is a low-level design question. You design a text editor with undo and redo and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Medium. Entry-level engineers can practise it, but it expects you to reason about requirements and trade-offs, not only list components.
- What should I cover first?
- Start with the use cases and the core entities, then the responsibilities of each one. Agree on scope with the interviewer before you design anything.
- Can I practise it for free?
- It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.
Related questions
Updated · Written by the SevyDevy team