Block Closing in EnterHandlerDelegate

Hello. I am wondering how I would go about implementing an auto block-closing feature, similar to when you press enter after opening a curly brace, but with keywords instead.

If I start a line with function hello() and then press enter, I would like the resulting code to be:

 

function hello()

    // Caret indented

endfunction

 

The main questions are:

  1.  How can I get the text / PsiElement of the current line in my EnterHandlerDelegate so I can check how it should be closed?
  2.  How can I force an indent when I press enter?
  3.  How can I add text after the newline? I have found file.add(psiElement), but I'm not sure how to create the element.

Thanks

1 comment
Comment actions Permalink

Sorry this got lost. See com.intellij.codeInsight.editorActions.enter.EnterAfterUnmatchedBraceHandler as reference implementation.

0

Please sign in to leave a comment.