diff --git a/src/Editor.hpp b/src/Editor.hpp index 301277c..606025a 100644 --- a/src/Editor.hpp +++ b/src/Editor.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(); diff --git a/src/History.cpp b/src/History.cpp new file mode 100644 index 0000000..1f99d65 --- /dev/null +++ b/src/History.cpp @@ -0,0 +1,5 @@ +// +// Created by miko on 06.03.17. +// + +#include "History.hpp" diff --git a/src/History.hpp b/src/History.hpp new file mode 100644 index 0000000..f871609 --- /dev/null +++ b/src/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(); + } + }; + +} \ No newline at end of file