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.

Bug 70915 - Editor does not reliably scroll to correct line when opening file at point
Summary: Editor does not reliably scroll to correct line when opening file at point
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Vitezslav Stejskal
URL:
Keywords: REGRESSION
: 72699 76619 87172 90877 117564 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-02 19:25 UTC by Jesse Glick
Modified: 2008-10-14 05:59 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2006-01-02 19:25:21 UTC
I have noticed in recent builds (incl. 5.0? not sure) that the editor no longer
scrolls to the caret when you open a Java file (at least) at a specific point.
E.g. when doing Find Usages and using F12 to jump to usages in previously
unopened files, the file opens and the caret is set correctly but it is
off-screen. If you press any arrow key (for example) then the view suddenly
scrolls to the right place.

I run JDK 6 on Linux and have the Java editor set to fold imports and initial
comments.
Comment 1 Miloslav Metelka 2006-01-08 14:59:38 UTC
Reproduced. I'll attempt to fix it.
Comment 2 Jesse Glick 2006-11-28 16:14:09 UTC
This still happens to me frequently, by the way.
Comment 3 Martin Grebac 2006-11-28 16:28:03 UTC
Raising to P2. This is really annoying behaviour and it leads users to think
that more functionality is broken, as it appears in refactoring, debugger, ...
Comment 4 Jesse Glick 2006-11-28 17:16:52 UTC
Said to also exist in 5.5?
Comment 5 Martin Grebac 2006-11-28 18:39:35 UTC
Yes, thanks, I didn't notice it's filed against 6.0. I'm experiencing the same
in 5.5. Would be good to have a fix this in 5.5.1.
Comment 6 Petr Hrebejk 2006-12-01 12:55:01 UTC
*** Issue 72699 has been marked as a duplicate of this issue. ***
Comment 7 Vitezslav Stejskal 2007-01-11 03:14:39 UTC
*** Issue 76619 has been marked as a duplicate of this issue. ***
Comment 8 Miloslav Metelka 2007-01-12 16:10:27 UTC
I've found the problem - the modelToView() returns null at BaseCaret:293 so the
caret bounds cannot be determined and the view does not scroll. I need to find
out why this happens.
Comment 9 Miloslav Metelka 2007-01-21 19:29:22 UTC
I further tracked the problem and at the time of calling setDot() from
SimpleRefactoringElementImpl the editor still has zero bounds i.e. getBounds()
returns empty rectangle. In such case BasicTextUI.getVisibleEditorRect() returns
null and the code does not inspect view's modelToView() at all.
I have also checked whether the DrawEngineDocView does not return zero preferred
span at the begining but the View.getPreferredSpan() gets called later than this
particular modelToView().
I have also tried to reorder the call to
getTopComponent(panes[0]).requestActive();
to be before the setting of the caret position but that did not help either.

I have workarounded the problem by posting the setDot() call into
SwingUtilities.invokeLater() in SimpleRefactoringElementImpl which helps.
Finally I have attempted a fix in caret that checks in paint() whether the
caret's offset was set but the caret bounds are still null and if so it
recomputes the bounds and scrolls the component if necessary. Although it's a
bit ugly to call things like scrolling from the paint() but it seems to work
fine. So I will leave this fix for now and if it would cause problems I will
roll it back and apply the SwingUtilities.invokeLater() fix.

Checking in BaseCaret.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseCaret.java,v  <--  BaseCaret.java
new revision: 1.128; previous revision: 1.127
Comment 10 Tim Lebedkov 2007-01-25 20:35:25 UTC
reproducible in netbeans-1915
Comment 11 Miloslav Metelka 2007-01-26 10:45:15 UTC
Tim, could you please mention the steps how to reproduce? Is it still clicking
Enter from Find Usages window or anything else? Thanks.
Comment 12 tkellerer 2007-01-26 11:02:37 UTC
I'm seeing this when using Goto-Source (Alt-O) or when during debugging when
using "Step Into" (F7)
Comment 13 Tim Lebedkov 2007-01-26 22:40:46 UTC
I have searched for "todo" in my sources and jumped to the found places from the
results window with double click. Important is probably that I have the options
"collapse initial comment" and "collapse imports" switched on.
Comment 14 Jesse Glick 2007-02-03 00:36:59 UTC
Also still not working well for me in 070202 under JDK 7 on Linux. I also fold
initial comments and imports. When I search for usages of
org.openide.util.Union2, two hits are in
core/bootstrap/src/org/netbeans/Module.java, in the import and in one real
usage. If I double-click the second usage, opening the file, the file opens and
momentarily displays the usage, but almost immediately the viewport switches to
lines 542-578. Pressing Right immediately switches the viewport to 508-544,
which is correct (the usage is on line 526). Lines 1-18 are the initial comment
and lines 22-39 are imports. That makes 34 fewer physical lines displayed when
folding, which is exactly the amount by which the viewport is initially wrong.
So clearly you need to update the viewport to scroll to the caret *after*
applying initial folds, or else make code folding correct the viewport position.
Comment 15 Miloslav Metelka 2007-02-19 21:15:24 UTC
*** Issue 90877 has been marked as a duplicate of this issue. ***
Comment 16 Miloslav Metelka 2007-02-26 22:22:35 UTC
I've made another fix to retain the relative position of the caret against the
visible view after fold hierarchy update. Hopefully this should fix the
remaining problems related to this issue:
Checking in libsrc/org/netbeans/editor/BaseCaret.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseCaret.java,v  <--  BaseCaret.java
new revision: 1.129; previous revision: 1.128
Comment 17 Vitezslav Stejskal 2007-03-20 04:25:10 UTC
*** Issue 87172 has been marked as a duplicate of this issue. ***
Comment 18 Tim Lebedkov 2007-04-06 16:20:36 UTC
reproducible in 070401

I searched for "StringBuffer" in my source files and double clicked in the
"Search Results" window on a line.

Linux, JDK 1.6.0_01
Comment 19 Vitezslav Stejskal 2007-10-05 10:45:10 UTC
*** Issue 117564 has been marked as a duplicate of this issue. ***
Comment 20 Vitezslav Stejskal 2007-10-05 14:20:21 UTC
Should work now after this and Mila's previous fixes in BaseCaret.

Checking in BaseCaret.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseCaret.java,v  <--  BaseCaret.java
new revision: 1.141; previous revision: 1.140
done
Comment 21 Vitezslav Stejskal 2008-10-13 12:53:09 UTC
*** Issue 76619 has been marked as a duplicate of this issue. ***
Comment 22 Vitezslav Stejskal 2008-10-13 12:54:43 UTC
This seems to have resurfaced again in recent dev builds. 
Comment 23 Vitezslav Stejskal 2008-10-13 15:27:26 UTC
http://hg.netbeans.org/main/rev/8bcee4facc8b
Comment 24 Quality Engineering 2008-10-14 05:59:00 UTC
Integrated into 'main-golden', will be available in build *200810140201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/8bcee4facc8b
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #70915 - fire fold hierarchy events to the listeners in the same order as they registered