|
7 | 7 | import org.fxmisc.richtext.model.TextChange; |
8 | 8 | import org.fxmisc.undo.UndoManager; |
9 | 9 | import org.fxmisc.undo.UndoManagerFactory; |
| 10 | +import org.fxmisc.undo.impl.MultiChangeUndoManagerImpl; |
| 11 | +import org.fxmisc.undo.impl.UnlimitedChangeQueue; |
| 12 | +import org.reactfx.SuspendableYes; |
10 | 13 | import org.reactfx.value.Val; |
11 | 14 |
|
12 | 15 | import javafx.beans.value.ObservableBooleanValue; |
@@ -121,6 +124,38 @@ public static <PS, SEG, S> UndoManager<List<RichTextChange<PS, SEG, S>>> richTex |
121 | 124 | preventMergeDelay); |
122 | 125 | }; |
123 | 126 |
|
| 127 | + /** |
| 128 | + * Returns an UndoManager with an unlimited history that can undo/redo {@link RichTextChange}s. New changes |
| 129 | + * emitted from the stream will not be merged with the previous change after {@link #DEFAULT_PREVENT_MERGE_DELAY} |
| 130 | + * <p><b>Note</b>: that <u>only styling changes</u> may occur <u>during suspension</u> of the undo manager. |
| 131 | + */ |
| 132 | + public static <PS, SEG, S> UndoManager<List<RichTextChange<PS, SEG, S>>> richTextSuspendableUndoManager( |
| 133 | + GenericStyledArea<PS, SEG, S> area, SuspendableYes suspendUndo) { |
| 134 | + return richTextSuspendableUndoManager(area, DEFAULT_PREVENT_MERGE_DELAY, suspendUndo); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Returns an UndoManager with an unlimited history that can undo/redo {@link RichTextChange}s. New changes |
| 139 | + * emitted from the stream will not be merged with the previous change after {@code preventMergeDelay}. |
| 140 | + * <p><b>Note</b>: that <u>only styling changes</u> may occur <u>during suspension</u> of the undo manager. |
| 141 | + */ |
| 142 | + public static <PS, SEG, S> UndoManager<List<RichTextChange<PS, SEG, S>>> richTextSuspendableUndoManager( |
| 143 | + GenericStyledArea<PS, SEG, S> area, Duration preventMergeDelay, SuspendableYes suspendUndo) { |
| 144 | + |
| 145 | + RichTextChange.skipStyleComparison( true ); |
| 146 | + |
| 147 | + return new MultiChangeUndoManagerImpl<> |
| 148 | + ( |
| 149 | + new UnlimitedChangeQueue<>(), |
| 150 | + TextChange::invert, |
| 151 | + applyMultiRichTextChange(area), |
| 152 | + TextChange::mergeWith, |
| 153 | + TextChange::isIdentity, |
| 154 | + area.multiRichChanges().conditionOn(suspendUndo), |
| 155 | + preventMergeDelay |
| 156 | + ); |
| 157 | + }; |
| 158 | + |
124 | 159 | /** |
125 | 160 | * Returns an UndoManager with an unlimited history that can undo/redo {@link PlainTextChange}s. New changes |
126 | 161 | * emitted from the stream will not be merged with the previous change |
|
0 commit comments