Abstract Styled Document and undo

W

wizard of oz

Hi all,

I'm extending an Abstract Styled Document associated with a JTextPanel to
implement a syntax highlighting editor. This is all working just fine -
except for undo / redo.

The problem is that the undo manager is recording my highlighting that
occurs as a result of keystrokes. So whenever the user performs undo, the
last operation (a colour highlight operation) is undone. Since I need to
refresh the highlighting when the undo is performed, the highlighting is
captured by the undo manager and this is the next undo operation in the undo
queue. Similar issue for redo. The colour highlighting is performed using:
javax.swing.text.DefaultStyledDocument.setCharacterAttributes (int offset,
int length, AttributeSet s, boolean replace);

What I've done to work around the problem is to remove the undomanager from
my document just before I perform the syntax scan then re add it immediately
afterwards. This effectively disables the capture of the syntax highlighting
changes. However ....

I'm not entirely sure that removing and adding the undo manager is the best
approach as, for various reasons, the syntax highlighting is performed in a
background thread. If the user happened to make a keystroke during that
time, then the keystroke also would not be captured by the undo manager.

So, is there a better way to prevent these colour highlights from being
registered in the undo manager's list?
I've looked at the UndoableEdit.die () method, but am not certain that I can
reliably distinguish between user actions and my internal syntax
highlighting changes.

TIA
woz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top