Skip to content

Commit

Permalink
Fix subtle bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Apr 27, 2017
1 parent f32c6cb commit 9a1d4dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ private void addChange(C change) {
if(merged.isPresent()) {
if (isIdentity.test(merged.get())) {
canMerge = false;
queue.push(); // clears the future
} else {
canMerge = true;
queue.push(merged.get());
}
} else {
canMerge = true;
queue.push(prev, change);
queue.next();
queue.push(change);
}
} else {
queue.push(change);
Expand Down
36 changes: 36 additions & 0 deletions undofx/src/test/java/org/fxmisc/undo/impl/UndoManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.concurrent.CountDownLatch;

import javafx.beans.property.SimpleIntegerProperty;

import org.fxmisc.undo.UndoManager;
import org.fxmisc.undo.UndoManager.UndoPosition;
import org.fxmisc.undo.UndoManagerFactory;
import org.junit.Test;
import org.reactfx.EventSource;
Expand Down Expand Up @@ -63,6 +65,40 @@ public void testMark() {
assertFalse(um.atMarkedPositionProperty().get());
}

@Test
public void testPositionValidAfterAddingAChange() {
EventSource<Integer> changes = new EventSource<>();
UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager(changes, c -> c, changes::push);

changes.push(1);
UndoPosition pos = um.getCurrentPosition();
changes.push(1);
assertTrue(pos.isValid());
}

@Test
public void testPositionInvalidAfterMerge() {
EventSource<Integer> changes = new EventSource<>();
UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager(
changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2));

changes.push(1);
UndoPosition pos = um.getCurrentPosition();
changes.push(1);
assertFalse(pos.isValid());
}

@Test
public void testRedoUnavailableAfterAnnihilation() {
EventSource<Integer> changes = new EventSource<>();
UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager(
changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2), c -> c == 0);

changes.push(1);
changes.push(-1);
assertFalse(um.isRedoAvailable());
}

@Test
public void zeroHistoryUndoManagerMark() {
EventSource<Integer> changes = new EventSource<>();
Expand Down

0 comments on commit 9a1d4dd

Please sign in to comment.