1818
1919import  com .intellij .codeInsight .daemon .impl .DefaultHighlightInfoProcessor ;
2020import  com .intellij .codeInsight .daemon .impl .ProgressableTextEditorHighlightingPass ;
21+ import  com .intellij .openapi .command .undo .UndoManager ;
2122import  com .intellij .openapi .editor .Editor ;
2223import  com .intellij .openapi .progress .ProgressIndicator ;
2324import  com .intellij .openapi .project .Project ;
2728
2829public  class  GoOptimizeImportsPass  extends  ProgressableTextEditorHighlightingPass  {
2930  @ NotNull  private  final  PsiFile  myFile ;
31+   private  Runnable  myRunnableFix ;
3032
3133  public  GoOptimizeImportsPass (@ NotNull  Project  project , @ NotNull  PsiFile  file , @ NotNull  Editor  editor ) {
3234    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
3638
3739  @ Override 
3840  protected  void  collectInformationWithProgress (@ NotNull  ProgressIndicator  progress ) {
41+     myRunnableFix  = new  GoImportOptimizer ().processFile (myFile );
3942    progress .checkCanceled ();
4043  }
4144
4245  @ Override 
4346  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 );
4651  }
4752}
0 commit comments