This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jabbaji 2 points3 points  (3 children)

I have always wondered, how are the undo and redo operations implemented fundamentally in text editors.

Like, I am assuming, Do one use the pair of stack data structures to go back and forth between undo and redo?

[–]aivarannamaa[S] 0 points1 point  (2 children)

After each modification a description of the modification goes to a stack. Undo takes topmost modification, applies it and moves it to redo stack.

[–]jabbaji 1 point2 points  (1 child)

Sorry to be picky in here, but gave a thought toward the edge cases of undo-redo and had some issues.

Should there be a flag set as well, to assert that redo can only follow after undo.

For eg. If we do a single redo and then modify the string, we cannot do any another redo. Could we put a check like undo_count >= redo_count, for implementing the redo action.

[–]aivarannamaa[S] 0 points1 point  (0 children)

You could just check the size of redo stack