Add undo system with coalescing logic and comprehensive tests.

- Implemented robust undo system supporting coalescing of text operations (insert, backspace, delete).
- Added `UndoSystem` integration into the editor/commands pipeline.
- Wrote extensive unit tests for various undo/redo scenarios, including multiline operations, cursor preservation, and history management.
- Refactored to ensure consistent cursor behavior during undo/redo actions.
- Updated CMake to include new tests.
This commit is contained in:
2026-02-10 22:39:55 -08:00
parent f3bdced3d4
commit ac0eadc345
6 changed files with 571 additions and 26 deletions

View File

@@ -33,6 +33,11 @@ public:
void UpdateBufferReference(Buffer &new_buf);
private:
enum class PendingAppendMode : std::uint8_t {
Append,
Prepend,
};
void apply(const UndoNode *node, int direction); // +1 redo, -1 undo
void free_node(UndoNode *node);
@@ -48,6 +53,8 @@ private:
void update_dirty_flag();
PendingAppendMode pending_mode_ = PendingAppendMode::Append;
Buffer *buf_;
UndoTree &tree_;
};