Skip to content

Conversation

@lpan
Copy link
Owner

@lpan lpan commented Sep 26, 2018

Motivation

I never got redo working because the previous method was hard to test and reason about. This seems like a reasonable size refactor. See if it can help me to get redo out 🙂

#34

Context

Currently, I am trying to implement undo and redo using two mutable stacks. One stack keeps track of all the applied "commands", the other is used as a temp buffer.

When an user action is committed, we would "push" it to the first stack. When the user undoes, we would "pop" the first stack (history stack), re-apply what is now on the first stack, and push the popped "command" onto the temp stack (redo stack).

For redo, we simply pop the redo stack, then apply the command and push it back to the history stack.

In my opinion, Mutating two logs is hard to reason about than just keeping track of the offsets of an append-only log.

What this PR does

This PR attempts to get rid of the two mutable stacks, and just use a single append-only log to store "commands" instead. We will use "offsets" of the log to implement the undo/redo logic.

@lpan lpan force-pushed the use-append-only-log branch from a1a5ceb to 94f35a6 Compare September 26, 2018 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants