diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-07-20 20:20:03 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-07-24 21:25:05 +0100 |
| commit | 03a4b3c73ff8cf7d37387df8bd0fcf9e895b59e0 (patch) | |
| tree | bdbbc01720925f962a6df5647c9a204175afe424 /src/buffer.cc | |
| parent | 3edd2c127c9d1754a487d76de38ec9b2c690ff7c (diff) | |
Support counts for undo/redo
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 08b857ce..028f9516 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -310,31 +310,38 @@ void Buffer::commit_undo_group() m_history_cursor = node; } -bool Buffer::undo() noexcept +bool Buffer::undo(size_t count) noexcept { commit_undo_group(); if (not m_history_cursor->parent) return false; - for (const Modification& modification : m_history_cursor->undo_group | reverse()) - apply_modification(modification.inverse()); + while (count-- and m_history_cursor->parent) + { + for (const Modification& modification : m_history_cursor->undo_group | reverse()) + apply_modification(modification.inverse()); + + m_history_cursor = m_history_cursor->parent; + } - m_history_cursor = m_history_cursor->parent; return true; } -bool Buffer::redo() noexcept +bool Buffer::redo(size_t count) noexcept { if (not m_history_cursor->redo_child) return false; kak_assert(m_current_undo_group.empty()); - m_history_cursor = m_history_cursor->redo_child.get(); + while (count-- and m_history_cursor->redo_child) + { + m_history_cursor = m_history_cursor->redo_child.get(); - for (const Modification& modification : m_history_cursor->undo_group) - apply_modification(modification); + for (const Modification& modification : m_history_cursor->undo_group) + apply_modification(modification); + } return true; } @@ -826,8 +833,8 @@ UnitTest test_undo{[]() buffer.commit_undo_group(); buffer.erase({2, 1}, {2, 5}); // change 5 buffer.commit_undo_group(); - buffer.undo(); - buffer.redo(); + buffer.undo(2); + buffer.redo(2); buffer.undo(); buffer.replace(2_line, buffer.end_coord(), "foo"); // change 6 buffer.commit_undo_group(); |
