diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java')
-rw-r--r-- | platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java index bbb1e163729e..19fb28086099 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterAction.java @@ -16,13 +16,13 @@ package com.intellij.codeInsight.editorActions.smartEnter; -import com.intellij.codeInsight.actions.BaseCodeInsightAction; import com.intellij.codeInsight.editorActions.enter.EnterAfterUnmatchedBraceHandler; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; @@ -41,15 +41,7 @@ import java.util.List; public class SmartEnterAction extends EditorAction { public SmartEnterAction() { super(new Handler()); - } - - @Override - protected Editor getEditor(@NotNull final DataContext dataContext) { - final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); - if (editor == null) return null; - Project project = editor.getProject(); - if (project == null) project = CommonDataKeys.PROJECT.getData(dataContext); - return project == null ? null : BaseCodeInsightAction.getInjectedEditor(project, editor); + setInjectedContext(true); } private static class Handler extends EditorWriteActionHandler { @@ -58,15 +50,15 @@ public class SmartEnterAction extends EditorAction { } @Override - public boolean isEnabled(Editor editor, DataContext dataContext) { - return getEnterHandler().isEnabled(editor, dataContext); + public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + return getEnterHandler().isEnabled(editor, caret, dataContext); } @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { + public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || editor.isOneLineMode()) { - plainEnter(editor, dataContext); + plainEnter(editor, caret, dataContext); return; } @@ -76,13 +68,13 @@ public class SmartEnterAction extends EditorAction { PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project); if (psiFile == null) { - plainEnter(editor, dataContext); + plainEnter(editor, caret, dataContext); return; } if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, caretOffset, psiFile.getFileType())) { EditorActionHandler enterHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER); - enterHandler.execute(editor, dataContext); + enterHandler.execute(editor, caret, dataContext); return; } @@ -100,13 +92,13 @@ public class SmartEnterAction extends EditorAction { } } if (!processed) { - plainEnter(editor, dataContext); + plainEnter(editor, caret, dataContext); } } } - public static void plainEnter(Editor editor, DataContext dataContext) { - getEnterHandler().execute(editor, dataContext); + public static void plainEnter(Editor editor, Caret caret, DataContext dataContext) { + getEnterHandler().execute(editor, caret, dataContext); } private static EditorActionHandler getEnterHandler() { |