|
6 | 6 | import java.util.concurrent.CountDownLatch;
|
7 | 7 |
|
8 | 8 | import javafx.beans.property.SimpleIntegerProperty;
|
| 9 | + |
9 | 10 | import org.fxmisc.undo.UndoManager;
|
| 11 | +import org.fxmisc.undo.UndoManager.UndoPosition; |
10 | 12 | import org.fxmisc.undo.UndoManagerFactory;
|
11 | 13 | import org.junit.Test;
|
12 | 14 | import org.reactfx.EventSource;
|
@@ -63,6 +65,40 @@ public void testMark() {
|
63 | 65 | assertFalse(um.atMarkedPositionProperty().get());
|
64 | 66 | }
|
65 | 67 |
|
| 68 | + @Test |
| 69 | + public void testPositionValidAfterAddingAChange() { |
| 70 | + EventSource<Integer> changes = new EventSource<>(); |
| 71 | + UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager(changes, c -> c, changes::push); |
| 72 | + |
| 73 | + changes.push(1); |
| 74 | + UndoPosition pos = um.getCurrentPosition(); |
| 75 | + changes.push(1); |
| 76 | + assertTrue(pos.isValid()); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testPositionInvalidAfterMerge() { |
| 81 | + EventSource<Integer> changes = new EventSource<>(); |
| 82 | + UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager( |
| 83 | + changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2)); |
| 84 | + |
| 85 | + changes.push(1); |
| 86 | + UndoPosition pos = um.getCurrentPosition(); |
| 87 | + changes.push(1); |
| 88 | + assertFalse(pos.isValid()); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testRedoUnavailableAfterAnnihilation() { |
| 93 | + EventSource<Integer> changes = new EventSource<>(); |
| 94 | + UndoManager um = UndoManagerFactory.unlimitedHistoryUndoManager( |
| 95 | + changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2), c -> c == 0); |
| 96 | + |
| 97 | + changes.push(1); |
| 98 | + changes.push(-1); |
| 99 | + assertFalse(um.isRedoAvailable()); |
| 100 | + } |
| 101 | + |
66 | 102 | @Test
|
67 | 103 | public void zeroHistoryUndoManagerMark() {
|
68 | 104 | EventSource<Integer> changes = new EventSource<>();
|
|
0 commit comments