Skip to content

Commit

Permalink
Fix UndoManager updating the same object multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Dec 28, 2021
1 parent 1e7b4ff commit f3ce2ca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions utiliti/src/main/java/de/gurkenlabs/utiliti/UndoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@ public void undo() {
}

final int currentOperation = this.undoStack[this.currentIndex].getOperation();
UndoState state = null;

int stepsUndone = 0;
this.executing = true;
try {
List<IMapObject> affectedTargets = new ArrayList<>();
do {
stepsUndone++;
state = this.undoStack[this.currentIndex];
affectedTargets.add(state.target);
final UndoState state = this.undoStack[this.currentIndex];
if (affectedTargets.stream().noneMatch(m -> m.getId() == state.target.getId())) {
affectedTargets.add(state.target);
}

switch (state.operationType) {
case ADD:
Expand Down Expand Up @@ -127,16 +128,19 @@ public void redo() {
}

final int currentOperation = this.undoStack[this.currentIndex + 1].getOperation();
UndoState state = null;

int stepsRedone = 0;
this.executing = true;
try {
List<IMapObject> affectedTargets = new ArrayList<>();
do {
++stepsRedone;
++this.currentIndex;
state = this.undoStack[this.currentIndex];
affectedTargets.add(state.target);

final UndoState state = this.undoStack[this.currentIndex];
if (affectedTargets.stream().noneMatch(m -> m.getId() == state.target.getId())) {
affectedTargets.add(state.target);
}

switch (state.operationType) {
case ADD:
Expand Down

0 comments on commit f3ce2ca

Please sign in to comment.