question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected change in UndoManager

See original GitHub issue

I’m getting the following exception from the UndoManager:

java.lang.IllegalArgumentException: Unexpected change received.
Expected:
[RichTextChange{
        position: 980
        removed: Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@d2a730f style=14,Georgia,0x000000ff)]
        inserted: Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
}]
Received:
[RichTextChange{
        position: 980
        removed: Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@53d2627e style=14,Georgia,0x000000ff), StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@2295669d style=14,Georgia,0x000000ff)]
        inserted: Par[[]; StyledSegment(segment=com.quollwriter.ui.fx.components.TextEditor$TextSegment@67d7424 style=14,Georgia,0x000000ff)]
}]
        at org.fxmisc.undo.impl.UndoManagerImpl.changeObserved(UndoManagerImpl.java:234)

This is because it is trying to undo a change to text that has a style that has not been recorded.

The style in this case is a “spelling error” indicator for a word.

I’m adding the style to the word using:

this.suspendUndos.suspendWhile (() -> {
   this.getContent ().setStyleSpans (r.getStart (), this.getContent ().getStyleSpans (r.getStart (), r.getEnd ()).mapStyles (ss -> {
   TextStyle _s = new TextStyle (ss);
    _s.setSpellingError (true);
    return _s;
 }));
  });

The suspendWhile is blocking the change from being recorded.

My undo manager is created using:

UndoManagerFactory.unlimitedHistoryFactory ().createMultiChangeUM(this.multiRichChanges ().conditionOn (this.suspendUndos), TextChange::invert, UndoUtils.applyMultiRichTextChange(this), TextChange::mergeWith, TextChange::isIdentity)

And my segment has the following equals method (which is returning true when it’s trying to do an undo):

@Override public boolean equals( Object obj )
{
    if ( obj == this )  return true;
    else if ( obj instanceof AbstractSegment && getClass().equals( obj.getClass() ) )
    {
        boolean v = getText().equals( ((AbstractSegment) obj).getText() );
        return v;
    }
    return false;
}

So the question is how can I add the spelling error style (which I don’t want to record in the undo list) but still have the undo work?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
garybentleycommented, Mar 12, 2020

Hi Jugen, Don’t worry I haven’t forgotten, I have just started a university degree and have been trying to get some free time to check this out. I’ve been following the discussion, just haven’t had chance to implement your fixes yet, I’m hoping to set aside some free time in the next couple of days to look into it.

1reaction
cengelscommented, Mar 11, 2020

Hey again. I tested the new richTextSuspendableUndoManager and found no issues or changes in behaviour compared to the unchecked one. From what I’ve been able to determine, it works just as well (but is now presumably safer).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up undoManager | Apple Developer Forums
I am trying to implement undoin a func, but the undoManager remains nil. ... Did you change the class of the window controller...
Read more >
Web Editing APIs/UndoManager Problem Descriptions - W3C
It must be possible to associate a set of DOM changes with a custom entry in the undo history. The changes might be...
Read more >
NSUndoManager - NSHipster
A method for reverting a change to an object, along with the arguments ... NSUndoManager -undo during a test may lead to unexpected...
Read more >
swift - undo method of UndoManager execute number of times ...
I would like to ask the following 2 points. ・Why this undo method executed number of times the registerUndo while testing? ・How to...
Read more >
Undo seems to fire a LOT of ChangedEvents? - GoJS
I'm trying to observe the changes made in an Undo action but it seems like a lot of unexpected events are fired when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found