added history draft

development
Michael Ochmann 8 years ago
parent baeb89fdb9
commit ba56dfc489
  1. 2
      src/Editor.hpp
  2. 5
      src/History.cpp
  3. 42
      src/History.hpp

@ -60,7 +60,7 @@ namespace groove {
return;
}
if (this->x >= this->buffer->linebuffer().at(this->y).length()) {
int length = this->buffer->linebuffer().at(this->y).length();
int length = static_cast<int>(this->buffer->linebuffer().at(this->y).length());
this->x = length > 0 ? length - 1 : 0;
}
this->scrollUp();

@ -0,0 +1,5 @@
//
// Created by miko on 06.03.17.
//
#include "History.hpp"

@ -0,0 +1,42 @@
#pragma once
#include <functional>
#include <memory>
namespace groove {
struct HistoryNode {
std::shared_ptr<HistoryNode> last;
std::shared_ptr<HistoryNode> next;
std::function<void()> undo, redo;
HistoryNode(std::function<void()> undo, std::function<void()> redo,
std::shared_ptr<HistoryNode> last = nullptr,
std::shared_ptr<HistoryNode> next = nullptr) :
undo(undo), redo(redo), last(last), next(next) {}
};
class History {
private:
std::shared_ptr<HistoryNode> begin;
std::shared_ptr<HistoryNode> end;
public:
History() : begin(nullptr), end(nullptr) {}
void push(std::function<void()> undo, std::function<void()> redo) {
this->end->next = std::make_shared<HistoryNode>(undo, redo, this->end);
}
void pop() {
this->end = this->end->last;
}
void undo() {
this->end->undo();
this->end = this->end->last;
}
void redo() {
this->end->redo();
}
};
}
Loading…
Cancel
Save