Add UndoSystem implementation and refactor UndoNode for simplicity.
This commit is contained in:
45
UndoSystem.h
Normal file
45
UndoSystem.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef KTE_UNDOSYSTEM_H
|
||||
#define KTE_UNDOSYSTEM_H
|
||||
|
||||
#include <string_view>
|
||||
#include "UndoTree.h"
|
||||
|
||||
class Buffer;
|
||||
|
||||
class UndoSystem {
|
||||
public:
|
||||
explicit UndoSystem(Buffer &owner, UndoTree &tree);
|
||||
|
||||
void Begin(UndoType type);
|
||||
|
||||
void Append(char ch);
|
||||
|
||||
void Append(std::string_view text);
|
||||
|
||||
void commit();
|
||||
|
||||
void undo();
|
||||
|
||||
void redo();
|
||||
|
||||
void mark_saved();
|
||||
|
||||
void discard_pending();
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
void apply(const UndoNode *node, int direction); // +1 redo, -1 undo
|
||||
void free_node(UndoNode *node);
|
||||
|
||||
void free_branch(UndoNode *node); // frees redo siblings only
|
||||
UndoNode *find_parent(UndoNode *from, UndoNode *target);
|
||||
|
||||
void update_dirty_flag();
|
||||
|
||||
private:
|
||||
Buffer &buf_;
|
||||
UndoTree &tree_;
|
||||
};
|
||||
|
||||
#endif // KTE_UNDOSYSTEM_H
|
||||
Reference in New Issue
Block a user