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
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