IDEA-56370 Spelchecker reacts on every key in json fixture file
authorMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Thu, 8 Jul 2010 16:59:35 +0000 (20:59 +0400)
committerMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Thu, 8 Jul 2010 17:01:04 +0000 (21:01 +0400)
plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java

index 5d934b230f0d85da3266185cd1dc4bc724903e69..dc00fef57bb8826a16ce9718df5d6f44b71b35f5 100644 (file)
@@ -17,12 +17,16 @@ package com.intellij.spellchecker.quickfixes;
 
 import com.intellij.codeInspection.ProblemDescriptor;
 import com.intellij.ide.DataManager;
+import com.intellij.injected.editor.EditorWindow;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
 import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
 import com.intellij.refactoring.actions.RenameElementAction;
 import com.intellij.refactoring.rename.NameSuggestionProvider;
@@ -79,13 +83,25 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix {
         if (provider != null) {
           provider.setActive(true);
         }
+   
         HashMap<String, Object> map = new HashMap<String, Object>();
         PsiElement psiElement = descriptor.getPsiElement();
-        map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement);
-        map.put(
-          LangDataKeys.EDITOR.getName(), 
-          InjectedLanguageUtil.openEditorFor(psiElement.getContainingFile(), project)
-        );
+        PsiFile containingFile = psiElement.getContainingFile();
+        Editor editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
+        
+        if (editor instanceof EditorWindow) {
+          map.put(LangDataKeys.EDITOR.getName(), editor);
+          map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement);
+        } else if (ApplicationManager.getApplication().isUnitTestMode()) { // TextEditorComponent / FiledEditorManagerImpl give away the data in real life
+          map.put(
+            LangDataKeys.PSI_ELEMENT.getName(), 
+            new TextEditorPsiDataProvider().getData(
+              LangDataKeys.PSI_ELEMENT.getName(),
+              editor, 
+              containingFile.getVirtualFile()
+            )
+          );
+        }
         
         DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext());
         AnAction action = new RenameElementAction();
@@ -98,7 +114,7 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix {
     };
     
     if (ApplicationManager.getApplication().isUnitTestMode()) fix.run();
-    else SwingUtilities.invokeLater(fix); // TODO [shkate] this is ugly, has problem with undo and hard to test!
+    else SwingUtilities.invokeLater(fix); // TODO [shkate] this is hard to test!
   }
 
 }
\ No newline at end of file