Bug 238202 - [EditorMgmt] Eclipse loses scroll position if tab is hidden
Summary: [EditorMgmt] Eclipse loses scroll position if tab is hidden
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 234566 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-23 22:58 EDT by Ducky Sherwood CLA
Modified: 2019-09-06 16:14 EDT (History)
4 users (show)

See Also:


Attachments
candidate patch (1.19 KB, patch)
2008-07-31 14:33 EDT, Boris Bokowski CLA
daniel_megert: review+
Details | Diff
Possible patch for JDT UI (906 bytes, text/plain)
2009-01-05 12:08 EST, Oleg Besedin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ducky Sherwood CLA 2008-06-23 22:58:03 EDT
Build ID: I20080609-1311

Steps To Reproduce:
1. Open a long file A.java.
2. Scroll to the end of the file.  DO NOT CLICK IN THE SOURCE ANYWHERE.
3. Open a bunch of other files, enough that A.java gets evicted from the list of visible tabs.
4. Press the back button as many times as you need to until A.java shows up again.

The source view will be positioned at the top of the file, not at the end of the file.


More information:
In an older version of Eclipse (that I modified for a user study), I fixed this by sticking the line
  page.getNavigationHistory().markLocation(page.getActiveEditor());

at the beginning of EditorManager.openEditor().  I believe that this creates another navigation entry every time you open a new tab, but IIRC the navigation entry list strips duplicates, and the performance hit was insignificant for me.  (YMMV.)
Comment 1 Boris Bokowski CLA 2008-06-24 19:23:10 EDT
I guess this is because we persist the cursor location and not (also) the current scroll position.
Comment 2 Boris Bokowski CLA 2008-06-24 19:25:20 EDT
I would classify this as an enhancement request (i.e.: persist scroll position in addition to cursor position), but I may be missing something. Dani, what do you think?
Comment 3 Dani Megert CLA 2008-06-30 09:31:49 EDT
You mean you don't want the last line and the caret to appear at the bottom right?

Moving to SWT as this is provided by StyledText.
Comment 4 Dani Megert CLA 2008-06-30 09:33:19 EDT
Forget the last comment, it was meant for another bug.
Comment 5 Dani Megert CLA 2008-06-30 10:44:37 EDT
The problem is not the scroll position: the location isn't recorded if the editor is deactivated. I guess we should also record the position before deactivating the  editor, otherwise this location gets lost as soon as that editor gets closed.

Simpler steps:
1. open a file
2. put caret somewhere
3. open another file
4. close first file
5. Back
==> first file is opened with caret at position 0.
Comment 6 Dani Megert CLA 2008-06-30 10:45:30 EDT
*** Bug 73224 has been marked as a duplicate of this bug. ***
Comment 7 Dani Megert CLA 2008-07-01 04:27:09 EDT
*** Bug 234566 has been marked as a duplicate of this bug. ***
Comment 8 Boris Bokowski CLA 2008-07-01 07:32:03 EDT
Dani, thanks for the investigation and explanation!
Comment 9 Boris Bokowski CLA 2008-07-31 14:32:22 EDT
(In reply to comment #5)
> Simpler steps:
> 1. open a file
> 2. put caret somewhere
> 3. open another file
> 4. close first file
> 5. Back
> ==> first file is opened with caret at position 0.

I could not reproduce this. I also could not reproduce using the steps from bug 234566.
Comment 10 Boris Bokowski CLA 2008-07-31 14:33:47 EDT
Created attachment 108889 [details]
candidate patch

This is the patch I wanted to test but couldn't because I was not able to reproduce.
Comment 11 Boris Bokowski CLA 2008-07-31 14:34:07 EDT
Moving to M2.
Comment 12 Dani Megert CLA 2008-08-06 04:47:23 EDT
>I could not reproduce this. I also could not reproduce using the steps from bug
>234566.
Well, you probably did too much in the "4. close first file" step ;-) I guess you first activated the editor by hitting the tab and then closed it. Instead, simply hover over the tab and hit the X to close the editor. That produces the bug for me using I20080805-1307.
Comment 13 Boris Bokowski CLA 2008-08-06 16:18:09 EDT
(In reply to comment #12)
> I guess you first activated the editor by hitting the tab and then closed it.

No, I did click on the "x" without first activating the editor. There must be something else that is different between your setup and mine.

Could you give the patch a try, does it fix the problem?

Comment 14 Dani Megert CLA 2008-08-07 03:42:13 EDT
>There must be something else that is different between your setup and mine.
Yes, I see the difference now: I can also not reproduce this on Linux but on my WindowsXP box, here my detailed steps for WindowsXP:
1. download and install I20080806-1800 into fresh directory
2. start with fresh workspace
3. create a Java project
4. import JUnit 3 or any other existing source (do not create the files as this
   already opens an editor)
5. in the Package Explorer double-click on any Java file
6. set caret somewhere
7. in the Package Explorer double-click on any Java file (other than in step 5)
8. click on the [X] of the other editor
9. hit the back arrow in the main toolbar
==> caret is a offset 0

NOTE: same problem when using single-click mode.
Comment 15 Dani Megert CLA 2008-08-07 03:45:39 EDT
Comment on attachment 108889 [details]
candidate patch

Boris, I looked at the patch: the code looks good to me and it also fixes the bug on my side.
Comment 16 Oleg Besedin CLA 2008-12-30 17:17:25 EST
I think there are two very different problems being mixed in this bug. 

The first problem is that scroll location is not saved; only cursor position is saved. This is the original bug description and comment 1, comment 2.

The second problem is about cursor position in case an editor has been closed (comment 5 and the rest).

Those are two different issues, so I opened a bug 259808 to track the cursor issue brought by Dani in the comment 5. 

Bug 234566 - changed to be a duplicate for the bug 259808.

On the "candidate patch": The navigation location for the "old" editor is already created whenever a "new" editor is activated. The problem found by Dani seems to be limited to editors being closed. It also does not address scroll position not being saved.

Let's use this bug to follow up on the scroll position issue and bug 259808 for the caret position issue.
Comment 17 Dani Megert CLA 2009-01-05 04:19:28 EST
*** Bug 234566 has been marked as a duplicate of this bug. ***
Comment 18 Dani Megert CLA 2009-01-05 04:19:55 EST
*** Bug 259808 has been marked as a duplicate of this bug. ***
Comment 19 Dani Megert CLA 2009-01-05 04:23:54 EST
Sorry Oleg, but you are wrong: this bug is and was about the the fact that the
editor is hidden (please read comment 0 again). The scroll position bug is a
known issue (bug 169838).
Comment 20 Dani Megert CLA 2009-01-05 04:29:23 EST
See also Oleg's comments and patch in bug 238202.
Comment 21 Dani Megert CLA 2009-01-05 11:39:30 EST
Oops sorry. This bug took a wrong turn in comment 3 where I assumed that the caret is set, which it isn't. So we have the following issues:

- this bug: scroll position not part of the navigation history
- my bug which Oleg newly reported as bug 238202
- restore bug 169838
Comment 22 Dani Megert CLA 2009-01-05 11:40:25 EST
>- my bug which Oleg newly reported as bug 238202
should read: "bug 259808"
Comment 23 Oleg Besedin CLA 2009-01-05 12:08:57 EST
Created attachment 121545 [details]
Possible patch for JDT UI

I think I found how to duplicate the problem. In my case folding was disabled for Java editors. Once I enabled folding, I can reproduce the problem with just two editors (no need to hide editor tab by opening a bunch of editors):

1. Make sure folding is enabled
2. Open long Java file, scroll to the end, do not click anywhere in the text
3. Open another Java file
4. Press back

Result: the original file is opened with scroll position reset to the beginning of the file. 
Expected: scroll position of the open editor is preserved

After some digging around I came across a place in JavaSourceViewer#setVisibleDocument(). The change in this patch fixes the scenario above for me.

The patch applies to org.eclipse.jdt.ui .

Dani, could you have a look at this patch? While the change seems logical to me, I am really not familiar with the JDT code around it.
Comment 24 Dani Megert CLA 2009-01-05 12:27:58 EST
It is intended that it scrolls back as the selection is marked and put into the navigation history and since scroll positions aren't part of it, it navigates back to that selection.

The proposed fix is bad and does not work since it no longer correctly sets the visible document: just open a Java file and see the incorrect folding states and the screen cheese (the squares all over the document).
Comment 25 Oleg Besedin CLA 2009-01-07 13:41:25 EST
Yes, the "Possible patch for JDT UI" is incorrect. 

The patch that fixes caret position is attached to the bug 259808. The source of confusion in duplication of Dani's scenario originated from enabling Java editor folding.

On the subject of scroll position (the original request in this bug): when navigation's Back/Forward is pressed:

  - Now: most of the time we go to the cursor position 

     (See TextSelectionNavigationLocation#restoreLocation(). We do 
     go back to the scroll position in some cases, such as if we have
     copyright header and its folding is disabled - which will 
     change if my fix for 259808 is used.)

  - Proposed in this bug:  we go to the scroll location

After thinking about this and playing with different alterations, I believe that the current behavior is actually better than what is proposed. 

For me, going back to the cursor position seems to be the action I'd prefer the *majority* of the time. So, from my habits of Eclipse use, I'd rather keep the current behavior.
Comment 26 Boris Bokowski CLA 2009-01-08 10:15:14 EST
So after finding bug 259808 (with a potential fix attached by Oleg), I believe we are back to:

(In reply to comment #2)
> I would classify this as an enhancement request (i.e.: persist scroll position
> in addition to cursor position)...

Removing target milestone as a result.
Comment 27 Boris Bokowski CLA 2009-11-17 13:07:28 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 28 Eclipse Webmaster CLA 2019-09-06 16:14:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.