diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java index d1ef02a44..16510d640 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java @@ -14,20 +14,6 @@ import org.jetbrains.annotations.NotNull; * @see com.intellij.openapi.actionSystem.AnAction */ public class EditorHandlerIllustration extends AnAction { - - /** - * This block of static code does not pertain to this class. - * It registers the custom MyTypedHandler, a TypedActionHandler - * that handles actions activated by typing in the editor. - * This registration code just needs to appear in a class (like AnAction class) - * that gets instantiated as part of IntelliJ startup. - */ - static { - final EditorActionManager actionManager = EditorActionManager.getInstance(); - final TypedAction typedAction = actionManager.getTypedAction(); - typedAction.setupHandler(new MyTypedHandler()); - } - /** * Clones a new caret at a higher Logical Position line number. * @param e Event related to this action diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java b/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java index 43e8fbb8c..49728d42b 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java @@ -2,31 +2,30 @@ package org.intellij.sdk.editor; -import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.codeInsight.editorActions.TypedHandlerDelegate; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.actionSystem.TypedActionHandler; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; /** - * This is a custom TypedActionHandler that handles actions activated + * This is a custom TypedHandlerDelegate that handles actions activated * keystrokes in the editor. * The execute method inserts a fixed string at Offset 0 of the document. * Document changes are made in the context of a write action. - * MyTypedHandler is registered by static code in the EditorHandlerIllustration class. - * - * @see com.intellij.openapi.editor.actionSystem.TypedActionHandler */ -class MyTypedHandler implements TypedActionHandler { +class MyTypedHandler extends TypedHandlerDelegate { + @NotNull @Override - public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { + public Result charTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { // Get the document and project final Document document = editor.getDocument(); - final Project project = editor.getProject(); // Construct the runnable to substitute the string at offset 0 in the document Runnable runnable = () -> document.insertString(0, "editor_basics\n"); // Make the document change in the context of a write action. WriteCommandAction.runWriteCommandAction(project, runnable); + return Result.STOP; } } diff --git a/editor_basics/src/main/resources/META-INF/plugin.xml b/editor_basics/src/main/resources/META-INF/plugin.xml index 8fe9d60e1..25a444dcc 100644 --- a/editor_basics/src/main/resources/META-INF/plugin.xml +++ b/editor_basics/src/main/resources/META-INF/plugin.xml @@ -61,4 +61,8 @@ + + + + \ No newline at end of file