diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-06-17 17:30:43 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-06-17 17:31:57 +1000 |
| commit | 5901d2e06b7c43fd0e6156a49761b81b747ea908 (patch) | |
| tree | 46a48c3f3341a7673f96bfb152c6f05703e04465 /src/buffer.hh | |
| parent | b2a853cfc2e52559b70d0ad3bfc4a49f3ed16833 (diff) | |
Revert "Switch undo storage from a tree to a plain list"
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U>
for selection undo/redo
This reverts commit e0d33f51b36c9f0be7ae2467dab455d211bbf561.
Diffstat (limited to 'src/buffer.hh')
| -rw-r--r-- | src/buffer.hh | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/buffer.hh b/src/buffer.hh index 415d32da..7b671c0e 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -123,6 +123,8 @@ public: }; friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; } + enum class HistoryId : size_t { First = 0, Invalid = (size_t)-1 }; + Buffer(String name, Flags flags, BufferLines lines, ByteOrderMark bom = ByteOrderMark::None, EolFormat eolformat = EolFormat::Lf, @@ -148,7 +150,9 @@ public: void commit_undo_group(); bool undo(size_t count = 1); bool redo(size_t count = 1); - size_t current_history_id() const noexcept { return m_history_id; } + bool move_to(HistoryId id); + HistoryId current_history_id() const noexcept { return m_history_id; } + HistoryId next_history_id() const noexcept { return (HistoryId)m_history.size(); } String string(BufferCoord begin, BufferCoord end) const; StringView substr(BufferCoord begin, BufferCoord end) const; @@ -241,14 +245,14 @@ public: struct HistoryNode : UseMemoryDomain<MemoryDomain::BufferMeta> { - HistoryNode(); + HistoryNode(HistoryId parent); + HistoryId parent; + HistoryId redo_child = HistoryId::Invalid; TimePoint committed; UndoGroup undo_group; }; - static constexpr size_t InvalidHistoryId = (size_t)-1; - const Vector<HistoryNode>& history() const { return m_history; } const UndoGroup& current_undo_group() const { return m_current_undo_group; } @@ -259,6 +263,7 @@ private: BufferCoord do_erase(BufferCoord begin, BufferCoord end); void apply_modification(const Modification& modification); + void revert_modification(const Modification& modification); struct LineList : BufferLines { @@ -284,12 +289,14 @@ private: Flags m_flags; Vector<HistoryNode> m_history; - size_t m_history_id = InvalidHistoryId; - size_t m_last_save_history_id = InvalidHistoryId; + HistoryId m_history_id = HistoryId::Invalid; + HistoryId m_last_save_history_id = HistoryId::Invalid; UndoGroup m_current_undo_group; - HistoryNode& current_history_node() { return m_history[m_history_id]; } - const HistoryNode& current_history_node() const { return m_history[m_history_id]; } + HistoryNode& history_node(HistoryId id) { return m_history[(size_t)id]; } + const HistoryNode& history_node(HistoryId id) const { return m_history[(size_t)id]; } + HistoryNode& current_history_node() { return m_history[(size_t)m_history_id]; } + const HistoryNode& current_history_node() const { return m_history[(size_t)m_history_id]; } Vector<Change, MemoryDomain::BufferMeta> m_changes; |
