From 025a6712bc9090aeea5517b61d4b51ac500864a0 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 12 Sep 2016 11:56:21 +0200 Subject: [PATCH] don't commit documents in move left/right action update (IDEA-161071) --- .../moveLeftRight/MoveElementLeftAction.java | 13 +++++++++++++ .../MoveElementLeftRightActionHandler.java | 7 +++---- .../moveLeftRight/MoveElementRightAction.java | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftAction.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftAction.java index 1093cf85fad6..5b28016b931c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftAction.java @@ -15,11 +15,24 @@ */ package com.intellij.codeInsight.editorActions.moveLeftRight; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.editor.actionSystem.EditorAction; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDocumentManager; +import org.jetbrains.annotations.NotNull; public class MoveElementLeftAction extends EditorAction { public MoveElementLeftAction() { super(new MoveElementLeftRightActionHandler(true)); setInjectedContext(true); } + + @Override + public void beforeActionPerformedUpdate(@NotNull AnActionEvent e) { + Project project = e.getProject(); + if (project != null) { + PsiDocumentManager.getInstance(project).commitAllDocuments(); + } + super.beforeActionPerformedUpdate(e); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftRightActionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftRightActionHandler.java index e2b7da0118e8..7b60039bf6e3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftRightActionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementLeftRightActionHandler.java @@ -61,10 +61,9 @@ public class MoveElementLeftRightActionHandler extends EditorWriteActionHandler if (project == null) return false; Document document = editor.getDocument(); if (!(document instanceof DocumentEx)) return false; - PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); - psiDocumentManager.commitDocument(document); - PsiFile file = psiDocumentManager.getPsiFile(document); - if (file == null || !file.isValid()) return false; + + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); + if (file == null) return false; PsiElement[] elementList = getElementList(file, caret.getSelectionStart(), caret.getSelectionEnd()); return elementList != null; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementRightAction.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementRightAction.java index 434e85179a8b..1702cb1cabc4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementRightAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/moveLeftRight/MoveElementRightAction.java @@ -15,11 +15,25 @@ */ package com.intellij.codeInsight.editorActions.moveLeftRight; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.editor.actionSystem.EditorAction; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDocumentManager; +import org.jetbrains.annotations.NotNull; public class MoveElementRightAction extends EditorAction { public MoveElementRightAction() { super(new MoveElementLeftRightActionHandler(false)); setInjectedContext(true); } + + @Override + public void beforeActionPerformedUpdate(@NotNull AnActionEvent e) { + Project project = e.getProject(); + if (project != null) { + PsiDocumentManager.getInstance(project).commitAllDocuments(); + } + super.beforeActionPerformedUpdate(e); + } + }