java - IntelliJ插件: Navigate from Project View to a file without triggering AutoScrollFromSource?

标签 java intellij-idea intellij-plugin

我正在编写一个 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/

相关文章:

java - 在 Java 应用程序中的 SOAPUI 测试中挂起线程

Java环境路径设置

java - 自定义 Spring Boot 配置文件未在 IntelliJ 中激活

intellij-idea - 想法 : How to chose what is shown in Project navigator?

intellij-idea - 如何在 IntelliJ 中导出所需的插件功能?

intellij-plugin - 如何以编程方式重新运行程序(intellij idea插件)

java - Gradle intelliJ 插件 SLF4J : Class path contains multiple SLF4J bindings

java - 使用括号的通用转换

java - UserAgentUtils 的替代品

windows - 无法删除一些 child 。发生这种情况的原因是,进程已打开文件或在目标目录中设置了工作目录