Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318095 - [explorer] [editor] cursor jumps and selection changes if I rename a global function or variable
Summary: [explorer] [editor] cursor jumps and selection changes if I rename a global f...
Status: RESOLVED WORKSFORME
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-26 15:12 EDT by Nitin Dahyabhai CLA
Modified: 2013-11-04 16:49 EST (History)
3 users (show)

See Also:


Attachments
proposed patch, only changes selection on inactive JS Editor parts (2.55 KB, patch)
2010-08-27 15:09 EDT, Nitin Dahyabhai CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nitin Dahyabhai CLA 2010-06-26 15:12:36 EDT
3.2 GA
Paste the following into a file and make sure it's completely expanded within the Explorer:
===================================================
com.example.class1.prototype.HHJH = function () {};
function class2jj() {
	
}
===================================================

Changing the name of one of these elements and then moving the cursor elsewhere, and this has to be really fast, results in the cursor moving back into the element name.


Thread [main] (Suspended (breakpoint at line 2376 in org.eclipse.jface.text.TextViewer))	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer(org.eclipse.jface.text.TextViewer).setSelectedRange(int, int) line: 2376	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer(org.eclipse.jface.text.source.SourceViewer).setRangeIndication(int, int, boolean) line: 1089	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer(org.eclipse.jface.text.source.projection.ProjectionViewer).setRangeIndication(int, int, boolean) line: 1342	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor(org.eclipse.ui.texteditor.AbstractTextEditor).setHighlightRange(int, int, boolean) line: 6033	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor).setSelection(org.eclipse.wst.jsdt.core.ISourceReference, boolean) line: 1913	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor).setSelection(org.eclipse.wst.jsdt.core.IJavaScriptElement) line: 1992	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.EditorUtility.revealInEditor(org.eclipse.ui.IEditorPart, org.eclipse.wst.jsdt.core.IJavaScriptElement) line: 190	
	org.eclipse.wst.jsdt.internal.ui.navigator.JavaFileLinkHelper.activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection) line: 37	
	org.eclipse.ui.internal.navigator.actions.LinkEditorAction$2.run() line: 78	
	org.eclipse.core.runtime.SafeRunner.run(org.eclipse.core.runtime.ISafeRunnable) line: 42	
	org.eclipse.ui.internal.navigator.actions.LinkEditorAction$1.runInUIThread(org.eclipse.core.runtime.IProgressMonitor) line: 76	
	org.eclipse.ui.progress.UIJob$1.run() line: 95	
	org.eclipse.swt.widgets.RunnableLock.run() line: 35	
	org.eclipse.ui.internal.UISynchronizer(org.eclipse.swt.widgets.Synchronizer).runAsyncMessages(boolean) line: 134	
	org.eclipse.swt.widgets.Display.runAsyncMessages(boolean) line: 4041	
	org.eclipse.swt.widgets.Display.readAndDispatch() line: 3660	
	org.eclipse.ui.internal.Workbench.runEventLoop(org.eclipse.jface.window.Window$IExceptionHandler, org.eclipse.swt.widgets.Display) line: 2629	
	org.eclipse.ui.internal.Workbench.runUI() line: 2593	
	org.eclipse.ui.internal.Workbench.access$4(org.eclipse.ui.internal.Workbench) line: 2427	
	org.eclipse.ui.internal.Workbench$7.run() line: 670	
	org.eclipse.core.databinding.observable.Realm.runWithDefault(org.eclipse.core.databinding.observable.Realm, java.lang.Runnable) line: 332	
	org.eclipse.ui.internal.Workbench.createAndRunWorkbench(org.eclipse.swt.widgets.Display, org.eclipse.ui.application.WorkbenchAdvisor) line: 663	
	org.eclipse.ui.PlatformUI.createAndRunWorkbench(org.eclipse.swt.widgets.Display, org.eclipse.ui.application.WorkbenchAdvisor) line: 149	
	org.eclipse.ui.internal.ide.application.IDEApplication.start(org.eclipse.equinox.app.IApplicationContext) line: 115	
	org.eclipse.equinox.internal.app.EclipseAppHandle.run(java.lang.Object) line: 196	
	org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(java.lang.Object) line: 110	
	org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(java.lang.Object) line: 79	
	org.eclipse.core.runtime.adaptor.EclipseStarter.run(java.lang.Object) line: 369	
	org.eclipse.core.runtime.adaptor.EclipseStarter.run(java.lang.String[], java.lang.Runnable) line: 179	
	sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method]	
	sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 39	
	sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 25	
	java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object...) line: 597	
	org.eclipse.equinox.launcher.Main.invokeFramework(java.lang.String[], java.net.URL[]) line: 619	
	org.eclipse.equinox.launcher.Main.basicRun(java.lang.String[]) line: 574	
	org.eclipse.equinox.launcher.Main.run(java.lang.String[]) line: 1407	
	org.eclipse.equinox.launcher.Main.main(java.lang.String[]) line: 1383	



Thread [main] (Suspended (breakpoint at line 2376 in org.eclipse.jface.text.TextViewer))	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer(org.eclipse.jface.text.TextViewer).setSelectedRange(int, int) line: 2376	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor).setSelection(org.eclipse.wst.jsdt.core.ISourceReference, boolean) line: 1959	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor).setSelection(org.eclipse.wst.jsdt.core.IJavaScriptElement) line: 1992	
	org.eclipse.wst.jsdt.internal.ui.javaeditor.EditorUtility.revealInEditor(org.eclipse.ui.IEditorPart, org.eclipse.wst.jsdt.core.IJavaScriptElement) line: 190	
	org.eclipse.wst.jsdt.internal.ui.navigator.JavaFileLinkHelper.activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection) line: 37	
	org.eclipse.ui.internal.navigator.actions.LinkEditorAction$2.run() line: 78	
	org.eclipse.core.runtime.SafeRunner.run(org.eclipse.core.runtime.ISafeRunnable) line: 42	
	org.eclipse.ui.internal.navigator.actions.LinkEditorAction$1.runInUIThread(org.eclipse.core.runtime.IProgressMonitor) line: 76	
	org.eclipse.ui.progress.UIJob$1.run() line: 95	
	org.eclipse.swt.widgets.RunnableLock.run() line: 35	
	org.eclipse.ui.internal.UISynchronizer(org.eclipse.swt.widgets.Synchronizer).runAsyncMessages(boolean) line: 134	
	org.eclipse.swt.widgets.Display.runAsyncMessages(boolean) line: 4041	
	org.eclipse.swt.widgets.Display.readAndDispatch() line: 3660	
	org.eclipse.ui.internal.Workbench.runEventLoop(org.eclipse.jface.window.Window$IExceptionHandler, org.eclipse.swt.widgets.Display) line: 2629	
	org.eclipse.ui.internal.Workbench.runUI() line: 2593	
	org.eclipse.ui.internal.Workbench.access$4(org.eclipse.ui.internal.Workbench) line: 2427	
	org.eclipse.ui.internal.Workbench$7.run() line: 670	
	org.eclipse.core.databinding.observable.Realm.runWithDefault(org.eclipse.core.databinding.observable.Realm, java.lang.Runnable) line: 332	
	org.eclipse.ui.internal.Workbench.createAndRunWorkbench(org.eclipse.swt.widgets.Display, org.eclipse.ui.application.WorkbenchAdvisor) line: 663	
	org.eclipse.ui.PlatformUI.createAndRunWorkbench(org.eclipse.swt.widgets.Display, org.eclipse.ui.application.WorkbenchAdvisor) line: 149	
	org.eclipse.ui.internal.ide.application.IDEApplication.start(org.eclipse.equinox.app.IApplicationContext) line: 115	
	org.eclipse.equinox.internal.app.EclipseAppHandle.run(java.lang.Object) line: 196	
	org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(java.lang.Object) line: 110	
	org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(java.lang.Object) line: 79	
	org.eclipse.core.runtime.adaptor.EclipseStarter.run(java.lang.Object) line: 369	
	org.eclipse.core.runtime.adaptor.EclipseStarter.run(java.lang.String[], java.lang.Runnable) line: 179	
	sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method]	
	sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 39	
	sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 25	
	java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object...) line: 597	
	org.eclipse.equinox.launcher.Main.invokeFramework(java.lang.String[], java.net.URL[]) line: 619	
	org.eclipse.equinox.launcher.Main.basicRun(java.lang.String[]) line: 574	
	org.eclipse.equinox.launcher.Main.run(java.lang.String[]) line: 1407	
	org.eclipse.equinox.launcher.Main.main(java.lang.String[]) line: 1383
Comment 1 Nitin Dahyabhai CLA 2010-08-27 15:09:01 EDT
Created attachment 177639 [details]
proposed patch, only changes selection on inactive JS Editor parts
Comment 2 Nitin Dahyabhai CLA 2010-08-27 15:09:58 EDT
Also reproducible just by changing the name of a global variable or top-level function.
Comment 3 Nitin Dahyabhai CLA 2010-08-31 11:37:34 EDT
* Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

Changing the selection while the user is typing is never OK.

* Is there a work-around? If so, why do you believe the work-around is insufficient? 

Disable the Link with Editor option from the Project Explorer, but it's on by default and not an obvious cause for the problem.

* How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

Manually tested.

* Give a brief technical overview. Who has reviewed this fix? 

Text changes in the name of a global in the editor triggers both an AST structure change and regular selection notification.  The AST change causes a partial refresh of the project explorer's contents and the editor's selection is then applied to the viewer.  The JSDT-contributed LinkHelper that's used to make sure the right editor and JS object are shown in the editor pane tries to reveal it, but the way it's written it also forces a change in selection.  And that's disastrous if the editor is active and the user is typing.

* What is the risk associated with this fix?

Low, adds a package-visible distinct method to reveal instead of reveal&select in the JS editor when it's not the active part.
Comment 4 Nitin Dahyabhai CLA 2010-09-01 00:32:34 EDT
Released
Comment 5 Chris Jaun CLA 2011-03-15 11:02:48 EDT
Nitin,

This fix broke the quick outline view.

"After the Quick outline opens, I can type a function name, then press Enter.
The function is shown in the Editor.
However, the cursor isn't placed there.
The annoying thing  is, if you now use the keyboard, the Editor jumps back to your previous edit location.
To browse the function you need to click with the mouse on it."

Specifically, line 190 in EditorUtility is causing this problem.
Comment 6 Chris Jaun CLA 2013-08-29 15:57:08 EDT
Can't reproduce in 3.5.1.
Comment 7 Stephane Wantiez CLA 2013-11-04 16:49:57 EST
I'm facing the problem today with Eclipse Juno SR1, and I'm becoming crazy with it.
I've renamed the object some hours ago, and now it's regularly jumping to the object variable declaration while I'm typing code...
I've restarted Eclipse several times, but the problem is still there...