This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I notice that with the 1.4.2 JVM, the caret lags about a character behind when I type quickly. Also, if I hold down the back key, the caret is one character behind (so empty space shows between the text and the caret as I delete). The problem is not evident with 1.4.1. It also does not seem to exist if I make the following modification in org\netbeans\editor\BaseCaret.java-- on line 426 uncomment the commented out line Utilities.runInEventDispatchThread( and comment out the following line SwingUtilities.invokeLater( However, the note above the code indicates that this was put in to fix a different problem. It seems that with the 1.4.2 JVM calling invokeLater causes the code to be executed too late, causing the Editor to appear to be slow. Here is the whole block of code in question, as my line numbers may be off-- /* part of fix of #18860 - Using runInEventDispatchThread () in AWT thread * means that the code is executed immediately which can lead * to problems once the insert/remove in document is performed * because the update() uses views to find out the visual position * and if the views doc listener is added AFTER the caret's listener * then the views are not updated yet. Using SwingUtilities.invokeLater() * should solve the problem although the view extent could flip * once the extent would be explicitely scrolled to area that does * not cover the caret's rectangle. It needs to be tested * so that it does not happen. */ Utilities.runInEventDispatchThread( // SwingUtilities.invokeLater( new Runnable() { public void run() { JTextComponent c2 = component; if (c2 != null) { BaseDocument doc = Utilities.getDocument(c2); if (doc != null) { doc.readLock(); try { // update(c2.getBounds(), scrollPolicy); update(scrollRect, scrollPolicy); } finally { doc.readUnlock(); } } } } } );
Although I understand the reason for the original fix I think that we should be able to improve the behavior into 3.6.
I have an idea how this could finally be fixed. The problem clearly is the document listeners ordering - the caret needs modelToView() to position itself but views (that are also listening on document like the caret does) may be fired later which causes that the caret finds the original views state. The solution could be to state an ordering for document listeners i.e. make several "layers" of document listeners with defined ordering of firing the listeners of the particular layers. I'll try to make a sketch of how this solution.
Can we fix this issue in 4.1? If not, please remove the status whiteboard I've added. Thanks.
I'll attempt to fix it now into 4.1.
I have a fix for the issue. As the fix adds a backward compatible change in friend API of editor/util module I'm asking DevRev for fasttrack review. The tests were created and apichanges.xml is updated accordingly.
Created attachment 21112 [details] Diff of the fix
Fixed in main trunk: Checking in fold/src/org/netbeans/modules/editor/fold/FoldHierarchyExecution.java; /cvs/editor/fold/src/org/netbeans/modules/editor/fold/FoldHierarchyExecution.java,v <-- FoldHierarchyExecution.java new revision: 1.6; previous revision: 1.5 done Checking in libsrc/org/netbeans/editor/BaseCaret.java; /cvs/editor/libsrc/org/netbeans/editor/BaseCaret.java,v <-- BaseCaret.java new revision: 1.109; previous revision: 1.108 done Checking in libsrc/org/netbeans/editor/BaseDocument.java; /cvs/editor/libsrc/org/netbeans/editor/BaseDocument.java,v <-- BaseDocument.java new revision: 1.119; previous revision: 1.118 done Checking in util/manifest.mf; /cvs/editor/util/manifest.mf,v <-- manifest.mf new revision: 1.6; previous revision: 1.5 done Checking in util/api/apichanges.xml; /cvs/editor/util/api/apichanges.xml,v <-- apichanges.xml new revision: 1.2; previous revision: 1.1 done RCS file: /cvs/editor/util/src/org/netbeans/lib/editor/util/PriorityListenerList.java,v done Checking in util/src/org/netbeans/lib/editor/util/PriorityListenerList.java; /cvs/editor/util/src/org/netbeans/lib/editor/util/PriorityListenerList.java,v <-- PriorityListenerList.java initial revision: 1.1 done RCS file: /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/DocumentListenerPriority.java,v done Checking in util/src/org/netbeans/lib/editor/util/swing/DocumentListenerPriority.java; /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/DocumentListenerPriority.java,v <-- DocumentListenerPriority.java initial revision: 1.1 done RCS file: /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java,v done Checking in util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java; /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java,v <-- DocumentUtilities.java initial revision: 1.1 done RCS file: /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/PriorityDocumentListenerList.java,v done Checking in util/src/org/netbeans/lib/editor/util/swing/PriorityDocumentListenerList.java; /cvs/editor/util/src/org/netbeans/lib/editor/util/swing/PriorityDocumentListenerList.java,v <-- PriorityDocumentListenerList.java initial revision: 1.1 done Checking in util/test/cfg-unit.xml; /cvs/editor/util/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.3; previous revision: 1.2 done RCS file: /cvs/editor/util/test/unit/src/org/netbeans/lib/editor/util/PriorityListenerListTest.java,v done Checking in util/test/unit/src/org/netbeans/lib/editor/util/PriorityListenerListTest.java; /cvs/editor/util/test/unit/src/org/netbeans/lib/editor/util/PriorityListenerListTest.java,v <-- PriorityListenerListTest.java initial revision: 1.1