diff --git a/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java b/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java index bb3b222b25b6..c07ff37053a6 100644 --- a/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java +++ b/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java @@ -26,7 +26,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; -import com.intellij.psi.util.PsiUtilBase; import com.intellij.spellchecker.util.SpellCheckerBundle; import org.jetbrains.annotations.NotNull; @@ -60,11 +59,8 @@ public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix { public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element == null) return; - Editor editor = PsiUtilBase.findEditor(element); - - if (editor == null) { - return; - } + final Editor editor = getEditor(element, project); + if (editor == null) return; TextRange textRange = ((ProblemDescriptorBase)descriptor).getTextRange(); final int documentLength = editor.getDocument().getTextLength(); @@ -85,8 +81,5 @@ public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix { items = lookupItems.toArray(items); LookupManager lookupManager = LookupManager.getInstance(project); lookupManager.showLookup(editor, items); - } - - } \ No newline at end of file diff --git a/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java b/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java index 4f2a21740969..cb1bab5b17b7 100644 --- a/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java +++ b/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java @@ -22,13 +22,10 @@ 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.editor.impl.EditorComponentImpl; 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; import com.intellij.refactoring.rename.RenameHandlerRegistry; @@ -37,9 +34,6 @@ import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.*; - - public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { public static final String FIX_NAME = "RenameTo"; @@ -83,15 +77,10 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { provider.setActive(true); } - Editor editor = getEditorFromFocus(); HashMap map = new HashMap<>(); PsiElement psiElement = descriptor.getPsiElement(); if (psiElement == null) return; - PsiFile containingFile = psiElement.getContainingFile(); - if (editor == null) { - editor = InjectedLanguageUtil.openEditorFor(containingFile, project); - } - + final Editor editor = getEditor(psiElement, project); if (editor == null) return; if (editor instanceof EditorWindow) { @@ -124,13 +113,4 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { public boolean startInWriteAction() { return false; } - - @Nullable - private static Editor getEditorFromFocus() { - final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (c instanceof EditorComponentImpl) { - return ((EditorComponentImpl)c).getEditor(); - } - return null; - } } \ No newline at end of file diff --git a/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java b/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java index 463b59ac1c01..33e2be8afa50 100644 --- a/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java +++ b/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java @@ -16,13 +16,19 @@ package com.intellij.spellchecker.quickfixes; import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.impl.EditorComponentImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Iconable; +import com.intellij.psi.PsiElement; +import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.spellchecker.SpellCheckerManager; import icons.SpellcheckerIcons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.awt.*; import java.util.List; @@ -49,4 +55,22 @@ public abstract class ShowSuggestions implements LocalQuickFix, Iconable { public Icon getIcon(int flags) { return SpellcheckerIcons.Spellcheck; } + + @Nullable + protected Editor getEditor(PsiElement element, @NotNull Project project) { + Editor editor = getEditorFromFocus(); + if (editor == null) { + editor = InjectedLanguageUtil.openEditorFor(element.getContainingFile(), project); + } + return editor; + } + + @Nullable + private static Editor getEditorFromFocus() { + final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (c instanceof EditorComponentImpl) { + return ((EditorComponentImpl)c).getEditor(); + } + return null; + } } diff --git a/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.after.java b/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.after.java new file mode 100644 index 000000000000..e9f6c55ee15e --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.after.java @@ -0,0 +1,6 @@ +import org.intellij.lang.annotations.Language; + +class InjectionChangeTo { + @Language("HTML") + String myString = "typo"; +} diff --git a/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.java b/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.java new file mode 100644 index 000000000000..95aa2c68bff6 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/InjectionChangeTo.java @@ -0,0 +1,6 @@ +import org.intellij.lang.annotations.Language; + +class InjectionChangeTo { + @Language("HTML") + String myString = "typppo"; +} diff --git a/spellchecker/testData/inspection/quickfixes/injectionChangeTo.after.xml b/spellchecker/testData/inspection/quickfixes/injectionChangeTo.after.xml new file mode 100644 index 000000000000..42c9b0ee98e5 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/injectionChangeTo.after.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/injectionChangeTo.xml b/spellchecker/testData/inspection/quickfixes/injectionChangeTo.xml new file mode 100644 index 000000000000..17f6e5d67fea --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/injectionChangeTo.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/JavaSpellCheckerFixesTest.java b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/JavaSpellCheckerFixesTest.java index 97e0aff331f3..38cdd12ce4a5 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/JavaSpellCheckerFixesTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/JavaSpellCheckerFixesTest.java @@ -23,4 +23,8 @@ public class JavaSpellCheckerFixesTest extends AbstractSpellCheckerFixesTest { public void testSimpleWordChangeTo() { doChangeToTest(); } + + public void testInjectionChangeTo() { + doChangeToTest(); + } } diff --git a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/XmlSpellCheckerFixesTest.java b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/XmlSpellCheckerFixesTest.java index 5ee39ada6890..4f6ddd4e5d55 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/XmlSpellCheckerFixesTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/XmlSpellCheckerFixesTest.java @@ -23,4 +23,8 @@ public class XmlSpellCheckerFixesTest extends AbstractSpellCheckerFixesTest { public void testSimpleWordChangeTo() { doChangeToTest(); } + + public void testInjectionChangeTo() { + doChangeToTest(); + } }