Project: Eclipse_Platform_UI
Bug 292427 [CommonNavigator] LinkEditorAction reacts to its own selection
Reported: 2009-10-15 12:17:40 | Status: verified fixed

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.13) Gecko/2009073022 (CK-IBM) Firefox/3.0.13 Build Identifier: M20090211-1700 1) when a user clicks on a tab in the editor area, LinkEditorAction selects the editor item in the CommonViewer 2) when a user selects an item in the CommonViewer, LinkEditorAction opens the editor in the editor are however LinkEditorAction does NOT ignore a selection change caused by itself--(1) also causes (2) this is not only a performance issue of reopening the editor, but it also causes a flaky situation because both 1 & 2 use UIJobs: 1)user clicks on an editor tab (editor A) and a UIJob is scheduled to select editor A in the CommonViewer 2)UIJob executes, causing selection to change which in turn causes a second UIJob to be scheduled to bring the editor to the top (the unnecessary UIJob) 3) but before this unnecessary UIJob executes (happens if loading A takes a while), the user clicks on editor B tab and a new UIJob is scheduled to change the selection in the CommonViewer to editor B 4) but it can't run until the unecessary UIJob runs (jobs are processed FIFO) 5) and when the unnecessary job does run, it sees that the current selection is still editor A so it brings A back to the top even the user had opened B the effect is if the user selects A before B has fully loaded, A will temporarily open, then flip back to B a suggested fix is to do this: 1) in LinkEditorAction#updateSelectionJob when LinkEditorAction changes the selection in the viewer (in reaction to a tab clicked in the editor area) it should save that selection: IStructuredSelection newSelection = linkService... ignoreSelection = newSelection; 2) and in LinkEditorAction#selectionChanged it should ignore that selection change public void selectionChanged(SelectionChangedEvent event) { if (commonNavigator.isLinkingEnabled() && event.getSelection() != ignoreSelection) { ignoreSelection = null; activateEditor(); } } Reproducible: Always Steps to Reproduce: 1. open two editors 2. turn on linking in common viewer 3. expand common viewer 4. click on the editor tab that isn't visible and before that editor fully loads (put a wait in it), click on the tab of the editor that was just open 5. Notice that the first editor opens temporarily, then flashes back to the second editor.

Files changed in fix:
bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/LinkHelperTest.java tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/NavigatorTestBase.java tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/NavigatorTestSuite.java tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/extension/TestLinkHelper.java