Skip to content

Undoing a multi change that modifies a later portion of the document before an earlier one fails #701

@JordanMartinez

Description

@JordanMartinez

Originally reported by @JFormDesigner in #695. Regression introduced by #695.

    @Test
    public void committing_relative_change_backToFront_works() {
        interact(() -> {
            String text = area.getText();
            String hello = "hello";
            String world = "world";
            area.createMultiChange(2)
                    .insertText(6, world)
                    .insertText(0, hello)
                    .commit();

            assertEquals(hello + text + world, area.getText());

            area.undo();
            assertEquals(text, area.getText());
        });
    }

Test output:

java.lang.IllegalArgumentException: Unexpected change received.
Expected:
[RichTextChange{
	position: 0
	removed: Par[; StyledSegment(segment=hello style=)]
	inserted: Par[; StyledSegment(segment= style=)]
}, RichTextChange{
	position: 6
	removed: Par[; StyledSegment(segment=world style=)]
	inserted: Par[; StyledSegment(segment= style=)]
}]
Received:
[RichTextChange{
	position: 0
	removed: Par[; StyledSegment(segment=hello style=)]
	inserted: Par[; StyledSegment(segment= style=)]
}, RichTextChange{
	position: 1
	removed: Par[; StyledSegment(segment=text) style=)]
	inserted: Par[; StyledSegment(segment= style=)]
}]
	org.fxmisc.undo.impl.UndoManagerImpl.changeObserved(UndoManagerImpl.java:255)
	org.reactfx.util.QueuingStreamNotifications.lambda$head$0(NotificationAccumulator.java:217)
	org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	org.reactfx.SuspendableBase.resume(SuspendableBase.java:64)
	org.reactfx.CloseableOnceGuard.close(Guard.java:49)
	org.reactfx.MultiGuard.close(Guard.java:83)
	org.reactfx.Suspendable$1.resumeSource(Suspendable.java:118)
	org.reactfx.Suspendable$1.suspendSource(Suspendable.java:104)
	org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$0(NotificationAccumulator.java:134)
	org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)
	org.reactfx.EventStreams$3.lambda$observeInputs$0(EventStreams.java:105)
	org.reactfx.value.ChangeListenerWrapper.accept(Val.java:786)
	org.reactfx.util.AbstractReducingStreamNotifications.lambda$head$0(NotificationAccumulator.java:248)
	org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	org.reactfx.value.ValBase.invalidate(ValBase.java:32)
	org.reactfx.SuspendableBoolean.release(SuspendableBoolean.java:24)
	org.reactfx.CloseableOnceGuard.close(Guard.java:49)
	org.reactfx.Suspendable.suspendWhile(Suspendable.java:49)
	org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.updateMulti(GenericEditableStyledDocumentBase.java:215)
	org.reactfx.util.Tuple3.exec(Tuple3.java:43)
	org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.replaceMulti(GenericEditableStyledDocumentBase.java:137)
	org.fxmisc.richtext.model.SimpleEditableStyledDocument.replaceMulti(SimpleEditableStyledDocument.java:1)
	org.fxmisc.richtext.GenericStyledArea.replaceMulti(GenericStyledArea.java:1202)
	org.fxmisc.richtext.MultiChangeBuilder.commit(MultiChangeBuilder.java:364)
	org.fxmisc.richtext.util.UndoUtils.lambda$10(UndoUtils.java:196)
	org.fxmisc.undo.impl.UndoManagerImpl.lambda$performChange$3(UndoManagerImpl.java:240)
	org.reactfx.Suspendable.suspendWhile(Suspendable.java:49)
	org.fxmisc.undo.impl.UndoManagerImpl.performChange(UndoManagerImpl.java:240)
	org.fxmisc.undo.impl.UndoManagerImpl.undo(UndoManagerImpl.java:152)
	org.fxmisc.richtext.UndoActions.undo(UndoActions.java:22)
	org.fxmisc.richtext.api.MultiChangeTest.lambda$2(MultiChangeTest.java:70)
	java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions