VISTALL / jsyntaxpane

Automatically exported from code.google.com/p/jsyntaxpane
0 stars 0 forks source link

caretUpdate() called before SyntaxDocument's internal state updated #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. launch SyntaxTester
2. type 1

What is the expected output? What do you see instead?
Expected: SyntaxTester.jEdtTestCaretUpdate() gets the number token from the
Document and displays it in lblToken.
Actual: SyntaxTester.jEdtTestCaretUpdate() gets a null token.

Please use labels and text to provide additional information.

The problem is that caretUpdate() is called during
SyntaxDocument.insertString()'s call to super.insertString(), which means
CaretListeners are called before SyntaxDocument.parse().  Since the
SyntaxDocument is only "half" updated, SyntaxDocument.getTokenAt() returns
a value that is out of date.

Original issue reported on code.google.com by javlo...@gmail.com on 14 Aug 2008 at 2:28

GoogleCodeExporter commented 9 years ago
I've attached a SyntaxDocument with a workaround.  I override the 
fireXXXupdate()
methods and queue the events until after the parse().  The CaretListeners are 
then
called when the document state is complete.

The workaround appears to work, but there might be some side effect since it 
reverses
the order of fireXXXUpdate() and fireUndoableEditUpdate() in
AbstractDocument.handleXXX() methods.

Original comment by javlo...@gmail.com on 14 Aug 2008 at 4:13

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report...
I've noticed this myself when testing some lexers with the tester, but did not 
bother
too much with it, as it did not seem that important.  I'll have another look.

Original comment by ayman.al...@gmail.com on 14 Aug 2008 at 5:43

GoogleCodeExporter commented 9 years ago
It only matters if a client wants to access the tokens in a CaretListener or
DocumentListener xxxUpdate() method.  I'm not sure how often that would happen, 
but
it would be nice if the document was in the right state when it does :)

Original comment by javlo...@gmail.com on 14 Aug 2008 at 6:54

GoogleCodeExporter commented 9 years ago
I managed to fix this in 0.9.2 by overriding the fireXXX methods of the 
SyntaDocument
instead of the inserUpdate and other methods.  This seems to fix the issue.
I'll group this change with some other fixes before releasing a binary.
The Source will be committed shortly.

Original comment by ayman.al...@gmail.com on 5 Oct 2008 at 10:13

GoogleCodeExporter commented 9 years ago
Now in 0.9.2 alpha and will be released.

Original comment by ayman.al...@gmail.com on 21 Oct 2008 at 8:30