TypedActionHandler with default typing behavior

I want to create a plugin that trigger typing event on editor without losing typing behavior.

The code I built is following

public class EditorIllustration extends AnAction {
    static {
        final EditorActionManager actionManager = EditorActionManager.getInstance();
        final TypedAction typedAction = actionManager.getTypedAction();
        typedAction.setupHandler(new MyTypedActionHandler());

public class MyTypedActionHandler implements TypedActionHandler {
    public void
execute(final Editor editor, final char c, DataContext dataContext) {
        final Document document = editor.getDocument();
        final Project project = editor.getProject();
        Runnable runnable = new Runnable() {
            public void
run() {
                insertCharacter(editor, document, c);
                // trigger plugin action
        WriteCommandAction.runWriteCommandAction(project, runnable);

    private void insertCharacter(Editor editor, Document document, char c) {
        CaretModel caretModel = editor.getCaretModel();
        document.insertString(caretModel.getOffset(), String.valueOf(c));
        caretModel.moveToOffset(caretModel.getOffset() + 1);

This does not work if the developer highlights words and types a character. (Highlighted words should be removed.)
I don't want to reinvent the default typing behavior.
Is there any other way to do this?

Thanks, in advance.

Comment actions Permalink

Yes. You need to use the TypedHandlerDelegate interface and the <typedHandler> extension point. In your implementation, return Result.CONTINUE.

Comment actions Permalink

This is what I want!
What I did is the followings.


<extensions defaultExtensionNs="com.intellij">

    <!-- Add your extensions here -->

    <typedHandler implementation="handler.MyTypedHandlerDelegate"/>



public class MyTypedHandlerDelegate extends TypedHandlerDelegate {
Result charTyped(char c, Project project, Editor editor, PsiFile file) {
        return Result.CONTINUE;



Please sign in to leave a comment.