Add UndoSystem implementation and refactor UndoNode for simplicity.
This commit is contained in:
48
UndoTree.cc
48
UndoTree.cc
@@ -1,47 +1,3 @@
|
||||
// Placeholder translation unit for UndoTree struct definition.
|
||||
// Undo logic is implemented in UndoSystem.
|
||||
#include "UndoTree.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
void
|
||||
UndoTree::Begin(const UndoKind kind, const size_t row, const size_t col)
|
||||
{
|
||||
if (this->pending != nullptr) {
|
||||
if (this->pending->Kind() == kind) {
|
||||
return;
|
||||
}
|
||||
this->Commit();
|
||||
}
|
||||
|
||||
assert(this->pending == nullptr);
|
||||
this->pending = new UndoNode(kind, row, col);
|
||||
assert(this->pending != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
UndoTree::Commit()
|
||||
{
|
||||
if (this->pending == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->root == nullptr) {
|
||||
assert(this->current == nullptr);
|
||||
|
||||
this->root = this->pending;
|
||||
this->current = this->pending;
|
||||
this->pending = nullptr;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
assert(this->current != nullptr);
|
||||
if (this->current->Next() != nullptr) {
|
||||
this->current->DeleteNext();
|
||||
}
|
||||
|
||||
this->current->Next(this->pending);
|
||||
this->current = this->pending;
|
||||
this->pending = nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user