Browse Source

Add limit to undo history (currently 500 actions).

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
c9e0b82204
2 changed files with 15 additions and 1 deletions
  1. +2
    -1
      include/history.hpp
  2. +13
    -0
      src/history.cpp

+ 2
- 1
include/history.hpp View File

@@ -4,6 +4,7 @@
#include <color.hpp>
#include <plugin/Model.hpp>
#include <vector>
#include <deque>
#include <jansson.h>


@@ -155,7 +156,7 @@ struct CableRemove : InverseAction<CableAdd> {


struct State {
std::vector<Action*> actions;
std::deque<Action*> actions;
int actionIndex;
/** Action index of saved patch state. */
int savedIndex;


+ 13
- 0
src/history.cpp View File

@@ -182,10 +182,23 @@ void State::clear() {
}

void State::push(Action* action) {
// Delete all future actions (if we have undone some actions)
for (int i = actionIndex; i < (int) actions.size(); i++) {
delete actions[i];
}
actions.resize(actionIndex);
// Delete actions from beginning if limit is reached
static const int limit = 500;
int n = (int) actions.size() - limit + 1;
if (n > 0) {
for (int i = 0; i < n; i++) {
delete actions[i];
}
actions.erase(actions.begin(), actions.begin() + n);
actionIndex -= n;
savedIndex -= n;
}
// Push action
actions.push_back(action);
actionIndex++;
// Unset the savedIndex if we just permanently overwrote the saved state


Loading…
Cancel
Save