Bug 165970 - [EditorMgmt] I somtimes need two Navigate->Back to get back to where I was
Summary: [EditorMgmt] I somtimes need two Navigate->Back to get back to where I was
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-27 15:54 EST by Boris Bokowski CLA
Modified: 2007-06-06 14:55 EDT (History)
3 users (show)

See Also:


Attachments
patch (1.72 KB, patch)
2006-11-29 10:40 EST, Boris Bokowski CLA
no flags Details | Diff
Fix (754 bytes, patch)
2007-01-31 09:53 EST, 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 Boris Bokowski CLA 2006-11-27 15:54:57 EST
[I20061024-1200]

Seems to be related to reusing editors.  Steps:

0. Set your editor preferences to:
   - Close editors automatically
   - Number of opened editors before closing: 1
1. Open SWT's Item.java or Item.class
2. select the getText() method
3. Hit Ctrl-T to display the method hierarchy
4. Pick TableItem's implementation of getText()
5. Hit Alt-Left

Expected: I get back to Item.getText()
Actual: The cursor is put at the top of TableItem, I have to hit Alt-Left again to go back to Item.getText().
Comment 1 Dani Megert CLA 2006-11-28 02:52:02 EST
Boris, the general navigation stuff is in Platform UI. Since you sent this to us: did you verify that this is not a Platform UI bug?
Comment 2 Boris Bokowski CLA 2006-11-29 10:40:15 EST
Created attachment 54718 [details]
patch

(In reply to comment #1)
> Boris, the general navigation stuff is in Platform UI. Since you sent this to
> us: did you verify that this is not a Platform UI bug?

No I didn't.  If I knew how this worked I would have.  My thinking was that it is JDT or text because I am seeing a superfluous location in my history.

Anyway, I looked at our code and found a suspicious asyncExec.  The attached patch solves my problem, but I am not sure about potential regressions.  Assuming you know how the navigation history works, could you have a look at the  patch and comment whether this appears safe?  (Perhaps we should try get rid of the asyncExec altogether?  It feels like a hack that can produce unpredictable behaviour.)
Comment 3 Boris Bokowski CLA 2006-12-04 15:50:47 EST
I have released my patch for now since it seems to fix a bug and I don't see how it could introduce new bugs.
Comment 4 Dani Megert CLA 2006-12-11 12:47:55 EST
This seems to fix the bug. Note that there's bug 154431 again but probably unrelated to this one.
Comment 5 Boris Bokowski CLA 2006-12-11 13:51:15 EST
Marking as fixed.
Comment 6 Boris Bokowski CLA 2006-12-14 15:55:49 EST
This is happening again.
Comment 7 Boris Bokowski CLA 2007-01-23 00:58:00 EST
Moving to JDT for comment - in JavaEditor.setSelection(), I see two calls of INavigationHistory.markLocation().  The relevant stack trace (package names omitted) of the first one looks like this:

at NavigationHistory.markLocation(NavigationHistory.java:212)
at AbstractTextEditor.markInNavigationHistory(AbstractTextEditor.java:5526)
at JavaEditor.setSelection(JavaEditor.java:2078)
at JavaEditor.setSelection(JavaEditor.java:2207)
at EditorUtility.revealInEditor(EditorUtility.java:183)
at JavaUI.openInEditor(JavaUI.java:672)
at OpenTypeAction.run(OpenTypeAction.java:65)

and for the second one:
at NavigationHistory.markLocation(NavigationHistory.java:212)
at AbstractTextEditor.markInNavigationHistory(AbstractTextEditor.java:5526)
at JavaEditor.setSelection(JavaEditor.java:2179)
at JavaEditor.setSelection(JavaEditor.java:2207)
at EditorUtility.revealInEditor(EditorUtility.java:183)
at JavaUI.openInEditor(JavaUI.java:672)
at OpenTypeAction.run(OpenTypeAction.java:65)

So setSelection() appears to call AbstractTextEditor.markInNavigationHistory two times.  The first call (line 2078) happens because textSelection.getOffset() returns 81, not 0 as one could expect.

To reproduce, set the maximum number of editor tabs to one and then use Ctrl-Shift-T twice, first on AbstractTreeViewer and then on TreeViewer.
Comment 8 Dani Megert CLA 2007-01-31 07:27:28 EST
This only happens on editor reuse otherwise it works just fine. I have to figure out why reuse makes a difference. We might get different (more?) selection change events.
Comment 9 Dani Megert CLA 2007-01-31 09:53:20 EST
Created attachment 57913 [details]
Fix

The problem is that the reuseEditor code calls the markNavigationHistory in the same chain as the input is set while during normal open this is posted async to the UI thread. The attached patch fixes this.
Comment 10 Boris Bokowski CLA 2007-01-31 10:03:58 EST
Thanks Dani!  Released >20060131.
Comment 11 Paul Webster CLA 2007-02-07 07:27:57 EST
In I20070206-0010
PW