Undo and redo in JTextPane Ignore style changes

I was wondering if there is a way to ignore text style changes in JTextPane when using Swing UndoManager?

+4
source share
1 answer

I have never tried, but I would suggest that you can create a custom UndoManager.

You need to override the method undoableEditHappend(...)to ignore the attribute change:

@Override
public void undoableEditHappened(UndoableEditEvent e)
{
    //  Check for an attribute change

    AbstractDocument.DefaultDocumentEvent event =
        (AbstractDocument.DefaultDocumentEvent)e.getEdit();

    if  (event.getType().equals(DocumentEvent.EventType.CHANGE))
        return
    else
        super.undoableEditHappened(e);
}
+2
source

Source: https://habr.com/ru/post/1623163/


All Articles