Commit a53551e5 authored by twanvl's avatar twanvl

don't merge actions that have been undone before, for example:

   typing1 Ctrl+Z Ctrl+Y typing2 Ctrl+Z
removes just typing2, not both.
parent 90efad4b
...@@ -18,6 +18,7 @@ DECLARE_TYPEOF_COLLECTION(ActionListener*); ...@@ -18,6 +18,7 @@ DECLARE_TYPEOF_COLLECTION(ActionListener*);
ActionStack::ActionStack() ActionStack::ActionStack()
: save_point(nullptr) : save_point(nullptr)
, last_was_add(false)
{} {}
ActionStack::~ActionStack() { ActionStack::~ActionStack() {
...@@ -36,6 +37,7 @@ void ActionStack::addAction(Action* action, bool allow_merge) { ...@@ -36,6 +37,7 @@ void ActionStack::addAction(Action* action, bool allow_merge) {
redo_actions.clear(); redo_actions.clear();
// try to merge? // try to merge?
if (allow_merge && !undo_actions.empty() && if (allow_merge && !undo_actions.empty() &&
last_was_add && // never merge with something that was redone once already
undo_actions.back() != save_point && // never merge with the save point undo_actions.back() != save_point && // never merge with the save point
undo_actions.back()->merge(*action) // merged with top undo action undo_actions.back()->merge(*action) // merged with top undo action
) { ) {
...@@ -43,6 +45,7 @@ void ActionStack::addAction(Action* action, bool allow_merge) { ...@@ -43,6 +45,7 @@ void ActionStack::addAction(Action* action, bool allow_merge) {
} else { } else {
undo_actions.push_back(action); undo_actions.push_back(action);
} }
last_was_add = true;
} }
void ActionStack::undo() { void ActionStack::undo() {
...@@ -54,6 +57,7 @@ void ActionStack::undo() { ...@@ -54,6 +57,7 @@ void ActionStack::undo() {
// move to redo stack // move to redo stack
undo_actions.pop_back(); undo_actions.pop_back();
redo_actions.push_back(action); redo_actions.push_back(action);
last_was_add = false;
} }
void ActionStack::redo() { void ActionStack::redo() {
assert(canRedo()); assert(canRedo());
...@@ -64,6 +68,7 @@ void ActionStack::redo() { ...@@ -64,6 +68,7 @@ void ActionStack::redo() {
// move to undo stack // move to undo stack
redo_actions.pop_back(); redo_actions.pop_back();
undo_actions.push_back(action); undo_actions.push_back(action);
last_was_add = false;
} }
bool ActionStack::canUndo() const { bool ActionStack::canUndo() const {
......
...@@ -114,6 +114,8 @@ class ActionStack { ...@@ -114,6 +114,8 @@ class ActionStack {
vector<Action*> redo_actions; vector<Action*> redo_actions;
/// Point at which the file was saved, corresponds to the top of the undo stack at that point /// Point at which the file was saved, corresponds to the top of the undo stack at that point
Action* save_point; Action* save_point;
/// Was the last thing the user did addAction? (as opposed to undo/redo)
bool last_was_add;
/// Objects that are listening to actions /// Objects that are listening to actions
vector<ActionListener*> listeners; vector<ActionListener*> listeners;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment