don't commit documents in "select in" actions update, use async commit when navigation from source (IDEA-160654)

This commit is contained in:
peter
2016-09-07 12:47:20 +02:00
parent 6bc26a8145
commit f978319ec3
3 changed files with 32 additions and 6 deletions
@@ -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;
}
@@ -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();
@@ -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) {