我正在编写一个 IntelliJ IDEA 插件,并且尝试从项目 Pane 导航到文件而不触发“autoscrollfromsource”功能(即使它已打开)。
我尝试暂时禁用 autoscrollfromsource(然后重新启用它),但这次尝试没有成功。
在下面的代码中,文件加载似乎需要一些时间,到那时 autoscrollfromsource 已经重新启用。
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);
}
});
}
}
有没有更好的方法可以导航到我的节点,而不触发 autoscrollfromsource?
感谢专业人士的提示:)
更新1
我将代码跟踪到 openapi 类 OpenFileDescriptor
,此处:
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();
}
基本上,我希望能够执行这个navigate
方法,而不触发源代码的自动滚动。
最佳答案
如果navigate(false)
还不够。您可以监听 FileEditorManager
事件,并阻止您打开的编辑器成为选定的编辑器。
关于java - IntelliJ插件: Navigate from Project View to a file without triggering AutoScrollFromSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20567413/