From f978319ec33893e79d3e7b64093416d8f7f43dd9 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 7 Sep 2016 12:34:12 +0200 Subject: [PATCH] don't commit documents in "select in" actions update, use async commit when navigation from source (IDEA-160654) --- .../com/intellij/ide/actions/SelectInAction.java | 11 +++++++++++ .../ide/actions/SelectInProjectViewAction.java | 11 +++++++++++ .../ide/projectView/impl/ProjectViewImpl.java | 16 ++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SelectInAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SelectInAction.java index 20deb878d5bc..30aae28bdffe 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SelectInAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SelectInAction.java @@ -28,6 +28,7 @@ import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.psi.PsiDocumentManager; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -41,6 +42,15 @@ public class SelectInAction extends AnAction implements DumbAware { invoke(e.getDataContext(), context); } + @Override + public void beforeActionPerformedUpdate(@NotNull AnActionEvent e) { + Project project = e.getProject(); + if (project != null) { + PsiDocumentManager.getInstance(project).commitAllDocuments(); + } + super.beforeActionPerformedUpdate(e); + } + @Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); @@ -100,6 +110,7 @@ public class SelectInAction extends AnAction implements DumbAware { @Override public PopupStep onChosen(final SelectInTarget target, final boolean finalChoice) { if (finalChoice) { + PsiDocumentManager.getInstance(mySelectInContext.getProject()).commitAllDocuments(); target.selectIn(mySelectInContext, true); return FINAL_CHOICE; } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SelectInProjectViewAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SelectInProjectViewAction.java index 5a79b637fd7c..5a03a4f04f75 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SelectInProjectViewAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SelectInProjectViewAction.java @@ -20,6 +20,8 @@ import com.intellij.ide.impl.ProjectPaneSelectInTarget; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDocumentManager; +import org.jetbrains.annotations.NotNull; /** * @author Konstantin Bulenkov @@ -34,6 +36,15 @@ public class SelectInProjectViewAction extends DumbAwareAction { } } + @Override + public void beforeActionPerformedUpdate(@NotNull AnActionEvent e) { + Project project = e.getProject(); + if (project != null) { + PsiDocumentManager.getInstance(project).commitAllDocuments(); + } + super.beforeActionPerformedUpdate(e); + } + @Override public void update(AnActionEvent e) { final Project project = e.getProject(); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index ddf5ebf2408f..a29637f8a36a 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -1674,12 +1674,14 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo } private void scrollFromFile(@NotNull PsiFile file, @Nullable Editor editor) { - final MySelectInContext selectInContext = new MySelectInContext(file, editor); + PsiDocumentManager.getInstance(myProject).performWhenAllCommitted(() -> { + final MySelectInContext selectInContext = new MySelectInContext(file, editor); - final SelectInTarget target = mySelectInTargets.get(getCurrentViewId()); - if (target != null && target.canSelect(selectInContext)) { - target.selectIn(selectInContext, false); - } + final SelectInTarget target = mySelectInTargets.get(getCurrentViewId()); + if (target != null && target.canSelect(selectInContext)) { + target.selectIn(selectInContext, false); + } + }); } @Override @@ -1735,7 +1737,9 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo PsiElement e = null; if (myEditor != null) { final int offset = myEditor.getCaretModel().getOffset(); - PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + if (PsiDocumentManager.getInstance(myProject).hasUncommitedDocuments()) { + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + } e = getPsiFile().findElementAt(offset); } if (e == null) {