Reputation: 40388
I'm writing an IntelliJ IDEA plugin and I am trying to navigate from the project pane to a file without triggering "autoscrollfromsource" function (even if it is turned on).
I tried temporarily disabling autoscrollfromsource (and re-enabling it afterwards) but this attempt was not successful.
In the code below, it seems it takes a moment for the file to load, and by that time autoscrollfromsource is already re-enabled.
private void navigateWithoutAutoscrollFromSource(final ProjectViewImpl projectView, BasePsiNode<? extends PsiElement> node) {
boolean wasAutoScrollFromSource = projectView.isAutoscrollFromSource(PROJECT_PANE);
if (wasAutoScrollFromSource) {
projectView.setAutoscrollFromSource(false, PROJECT_PANE);
}
// this navigation here should NOT trigger autoscrollfromsource!!
node.navigate(true);
if (wasAutoScrollFromSource) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
projectView.setAutoscrollFromSource(true, PROJECT_PANE);
}
});
}
}
Is there a better way to navigate to my node, without triggering autoscrollfromsource?
Thanks for any pro tips :)
Update 1
I trace the code to the openapi class OpenFileDescriptor
, here:
public void navigate(boolean requestFocus) {
if (!canNavigate()) {
throw new IllegalStateException("Navigation is not possible with null project");
}
if (!myFile.isDirectory() && navigateInEditor(myProject, requestFocus)) return;
navigateInProjectView();
}
Basically, I would like to be able to execute this navigate
method, without it triggering autoscroll from source.
Upvotes: 2
Views: 274
Reputation: 8216
If navigate(false)
isn't enough. You can listen for FileEditorManager
events, and stop the editor you open from becoming the selected editor.
Upvotes: 2