Add UndoSystem implementation and refactor UndoNode for simplicity.

This commit is contained in:
2025-11-30 00:04:29 -08:00
parent e91a32dd90
commit 35ffe6d11c
20 changed files with 13950 additions and 1479 deletions

View File

@@ -2,81 +2,25 @@
#define KTE_UNDONODE_H
#include <cstddef>
#include <cstddef>
#include <cstdint>
#include <string>
enum UndoKind {
UNDO_INSERT,
UNDO_DELETE,
enum class UndoType : uint8_t {
Insert,
Delete,
Paste,
Newline,
DeleteRow,
};
class UndoNode {
public:
explicit UndoNode(const UndoKind kind, const size_t row, const size_t col)
: kind_(kind), row_(row), col_(col) {}
~UndoNode() = default;
[[nodiscard]] UndoKind Kind() const
{
return kind_;
}
[[nodiscard]] UndoNode *Next() const
{
return next_;
}
void Next(UndoNode *next)
{
next_ = next;
}
[[nodiscard]] UndoNode *Child() const
{
return child_;
}
void Child(UndoNode *child)
{
child_ = child;
}
void SetRowCol(const std::size_t row, const std::size_t col)
{
this->row_ = row;
this->col_ = col;
}
[[nodiscard]] std::size_t Row() const
{
return row_;
}
[[nodiscard]] std::size_t Col() const
{
return col_;
}
void DeleteNext() const;
private:
[[maybe_unused]] UndoKind kind_;
[[maybe_unused]] UndoNode *next_{nullptr};
[[maybe_unused]] UndoNode *child_{nullptr};
[[maybe_unused]] std::size_t row_{}, col_{};
struct UndoNode {
UndoType type{};
int row{};
int col{};
std::string text;
UndoNode *child = nullptr; // next in current timeline
UndoNode *next = nullptr; // redo branch
};