Bug 93845 - [navigation] Unnecessary scroll on editor open
Summary: [navigation] Unnecessary scroll on editor open
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, polish
: 96782 (view as bug list)
Depends on: 97366
Blocks:
  Show dependency tree
 
Reported: 2005-05-05 15:43 EDT by Steve Northover CLA
Modified: 2007-05-16 09:27 EDT (History)
7 users (show)

See Also:


Attachments
Patch to be applied to org.eclipse.ui.workbench.texteditor (14.34 KB, patch)
2005-05-28 06:24 EDT, Dani Megert CLA
no flags Details | Diff
Patch to be applied org.eclipse.jdt.ui (15.81 KB, patch)
2005-05-28 06:24 EDT, Dani Megert CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Northover CLA 2005-05-05 15:43:55 EDT
1. Open a type hierarchy
2. Double click on a class which is not currently open
3. The editor opens first scrolled to the top of the file -- watch for
    the *** from the javadoc comment
4. Witness the editor scroll down to the class definition

This is a really rapid flash on Windows, and the effect is more visible on 
Linux-GTK.
Comment 1 Tom Hofmann CLA 2005-05-06 04:16:59 EDT
code is in OpenActionUtil.open(Object,boolean)

moving to jdt-ui.
Comment 2 Dirk Baeumer CLA 2005-05-06 06:59:57 EDT
Actually, there is little we can do here. The current API only allows use to
open the editor and then reveal the element. What would be needed is additional
API to do this in one call. Alternatively we couldn't reveal the element but I
think that would be a real disadvantage.

Moving back to text to consider the additional API.
Comment 3 Steve Northover CLA 2005-05-06 07:55:11 EDT
I'm pretty sure that wrapping the whole thing in a setRedraw() would hide the 
flash.
Comment 4 Tom Hofmann CLA 2005-05-06 08:12:09 EDT
(In reply to comment #3)
> I'm pretty sure that wrapping the whole thing in a setRedraw() would hide the 
> flash.

Yes - but the editor is opened by IDE.openEditor and already there when we set
the selection. Fixing this bug would require new API with Platform-UI to allow
to open an editor on an initial selection.
Comment 5 Steve Northover CLA 2005-05-06 08:17:17 EDT
Ok.  I think the problem has been there since 2.1 so it isn't a regression.
Comment 6 Dani Megert CLA 2005-05-12 04:55:34 EDT
The only thing we could do (besides adding new API, see bug ) is to create a
temporary marker, use IDE.openEditor(..., IMarker,...) and delete the marker
afterwards but since creating a marker isn't for free I'm reluctant of doing so.
In addition we can no longer use JavaEditor.setSelection(IJavaElement) which
does some optimization for the Java outline page.

Moving to Platform UI to consider adding the new API:
  IDE.openEditor(...,ISelection,...)
Comment 7 Tom Hofmann CLA 2005-05-12 06:22:44 EDT
AFAICS, the code in IDE.openEditor(... IMarker) does not (and cannot) perform
anything more as long as there is no editor API from our side that allows to set
an initial selection.
Comment 8 Dani Megert CLA 2005-05-12 08:50:59 EDT
I see another solution that could work without additional API:

- the text editors extract the selection from the editor input via
IEditorInput.getAdapter(ISelection.class) [or some other interface] and handle
the initial setting of
- we create our own IFileEditorInput that implements provides the adapter and
allows to set the initial selection upon creation.

It would help if the restriction on FileEditorInput saying that it is not
intended to be subclassed is removed. Otherwise we have to copy the code instead
of just subclassing the existing class.

I'm taking the bug back to investigate this further.
Comment 9 Dani Megert CLA 2005-05-13 07:20:41 EDT
To make it happen for 3.1 we need to subclass FileEditorInput because if we
provide our own implementation (i.e. copy the code)  clients that currently
use/cast to FileEditorInput (instead of IFileEditorInput) would be broken (there
were similar places even inside the Eclipse SDK - see corresponding bug reports)
and it's a bit late in the game to do such a change now.

Michael, Platform UI already subclasses FileEditorInput (I know this is done
inside the same plug-in but it's against the spec nevertheless ;-)

In addition there exist already other subclasses (one in JDT UI and one in PDE UI).
Comment 10 Michael Van Meekeren CLA 2005-05-19 10:49:39 EDT
nick can you comment on comment #9
Comment 11 Nick Edgar CLA 2005-05-19 15:03:22 EDT
I'm fine with allowing subclassing of FileEditorInput, but if what we're doing
is a workaround anyway, I don't see the API change as essential for 3.1.
The right answer would be to allow an initial selection to be passed to
openEditor, in addition to the input.

Also note that subclasses of FileEditorInput should be careful to handle
persistence properly.  They'll likely need to specify a different factory if
maintaining extra state besides the IFile.
Comment 12 Dani Megert CLA 2005-05-19 15:38:16 EDT
I'm fine with an internal blessing and move to the correct solution for 3.2.
Comment 13 Nick Edgar CLA 2005-05-19 15:51:06 EDT
I've filed bug 96019 and bug 96021 for the persistence problems.
Comment 14 Nick Edgar CLA 2005-05-19 15:57:42 EDT
If the subclass's selection is just going to be used when the editor is first
opened, the selection should not be persisted.  Or if it is, it should probably
not be honoured when the editor is restored, since it's likely that the user
changed the selection.  It's probably less surprising to have the editor
restored at the top then at the selection when it was first opened.  Ideally the
editor's current selection would be persisted too, but editors unfortunately do
not support saveState(IMemento) like views do (there's a PR for this already).
Comment 15 Dani Megert CLA 2005-05-19 16:09:37 EDT
I only see this as a hack to fix the flash for 3.1. No plans to provide
persistency code for 3.1.
Comment 16 Steve Northover CLA 2005-05-24 10:48:22 EDT
A hack fix at this time is good for me so long as it doesn't involve API or 
something that can't easily be fixed the right way after 3.1.
Comment 17 Dani Megert CLA 2005-05-27 12:29:53 EDT
I've a version ready which fixes the vertical scrolling. The problem now is that
it upon opening it shifts the styled text widget to the right which I do not
really understand and which looks quite ugly. Maybe someone from the SWT team
(Steve ;-) could take a look at this. I can provide my current state either as
patch or a plug-in export (to big to attach) It might be related with the
layoutting of the text viewer and looks as if the ruler width is applied at a
later point to the viewer and hence the text widget shifted to the right.

Moving target milestone to RC2 to investigate this further. If we can pin down
the horizontal shiftting we have a really good improvement here.

The current changes to not require additional API.
Comment 18 Steve Northover CLA 2005-05-27 18:36:45 EDT
Attach the patch or release the code with a flag or property we can use to 
turn it on and we will look at it.  Does it scroll on all platforms?
Comment 19 Dani Megert CLA 2005-05-28 06:14:12 EDT
It's no longer a "flash" but rather just shifting it to the right. What I think
is happening is that before the styled text widget with the rulers on the left
and right was created with caret a position 0 just afterwards we've set the
selection inside a setRedraw(false/true). This caused the vertical flash plus
the scroll bar jumping. Now we set the selection during viewer creation and
there's no setRedraw(false/true) involved on our side. Even if I surround the
whole creation code (i.e. before setting the contents to the text widget) with
setRedraw(false/true) I see the thext inside the widget being moved.

Patches coming...
Comment 20 Dani Megert CLA 2005-05-28 06:24:03 EDT
Created attachment 21918 [details]
Patch to be applied to org.eclipse.ui.workbench.texteditor
Comment 21 Dani Megert CLA 2005-05-28 06:24:38 EDT
Created attachment 21919 [details]
Patch to be applied org.eclipse.jdt.ui
Comment 22 Steve Northover CLA 2005-05-30 14:35:26 EDT
I am able to make it happen on Windows when selecting files in the hierarchy 
view.  It does not happen in the packages view.  In that view, it doesn't 
scroll to show the class.  Is different code running?

FH and SN to look into what is happening.
Comment 23 Dani Megert CLA 2005-05-30 15:54:13 EDT
>packages view
Package Explorer?
Comment 24 Steve Northover CLA 2005-05-30 17:03:22 EDT
Yes.
Comment 25 Felipe Heidrich CLA 2005-05-30 17:25:41 EDT
Bug in StyledText, a capture it in Bug 97366
Comment 26 Dani Megert CLA 2005-05-31 04:26:24 EDT
I also see it using the Package Explorer.
Comment 27 Steve Northover CLA 2005-06-03 17:41:44 EDT
Ok, defer this for 3.1.  It's too dangerous to change right now.
Comment 28 Dani Megert CLA 2005-06-04 10:00:53 EDT
Setting to REMIND until the blocking bug is fixed.
Comment 29 Dani Megert CLA 2005-06-08 04:28:23 EDT
*** Bug 96782 has been marked as a duplicate of this bug. ***
Comment 30 Dani Megert CLA 2007-05-16 02:31:49 EDT
Steve, OK to close this as this happens in SWT which decided not to fix this?
Comment 31 Steve Northover CLA 2007-05-16 08:14:03 EDT
Sure.
Comment 32 Dani Megert CLA 2007-05-16 09:27:00 EDT
.
Comment 33 Dani Megert CLA 2007-05-16 09:27:54 EDT
WONTFIX, see bug 96782.