18
18
19
19
import com .intellij .codeInsight .daemon .impl .DefaultHighlightInfoProcessor ;
20
20
import com .intellij .codeInsight .daemon .impl .ProgressableTextEditorHighlightingPass ;
21
+ import com .intellij .openapi .command .undo .UndoManager ;
21
22
import com .intellij .openapi .editor .Editor ;
22
23
import com .intellij .openapi .progress .ProgressIndicator ;
23
24
import com .intellij .openapi .project .Project ;
27
28
28
29
public class GoOptimizeImportsPass extends ProgressableTextEditorHighlightingPass {
29
30
@ NotNull private final PsiFile myFile ;
31
+ private Runnable myRunnableFix ;
30
32
31
33
public GoOptimizeImportsPass (@ NotNull Project project , @ NotNull PsiFile file , @ NotNull Editor editor ) {
32
34
super (project , editor .getDocument (), "Go Optimize Imports Pass" , file , editor , file .getTextRange (), false ,
@@ -36,12 +38,15 @@ public GoOptimizeImportsPass(@NotNull Project project, @NotNull PsiFile file, @N
36
38
37
39
@ Override
38
40
protected void collectInformationWithProgress (@ NotNull ProgressIndicator progress ) {
41
+ myRunnableFix = new GoImportOptimizer ().processFile (myFile );
39
42
progress .checkCanceled ();
40
43
}
41
44
42
45
@ Override
43
46
protected void applyInformationWithProgress () {
44
- final Runnable runnable = new GoImportOptimizer ().processFile (myFile );
45
- DocumentUtil .writeInRunUndoTransparentAction (runnable );
47
+ final Project project = myFile .getProject ();
48
+ UndoManager undoManager = UndoManager .getInstance (project );
49
+ if (undoManager .isUndoInProgress () || undoManager .isRedoInProgress ()) return ;
50
+ DocumentUtil .writeInRunUndoTransparentAction (myRunnableFix );
46
51
}
47
52
}
0 commit comments