Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
handling removal of \n after pressing tab on autocomplete option. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kashishm committed Aug 11, 2015
1 parent 821fbe5 commit b626336
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.intellij.codeInsight.template.TemplateBuilder;
import com.intellij.codeInsight.template.TemplateBuilderFactory;
import com.intellij.openapi.module.Module;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ProcessingContext;
Expand Down Expand Up @@ -69,6 +70,10 @@ public void addCompletions(@NotNull final CompletionParameters parameters, Proce
element = element.withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
if (context.getCompletionChar() == '\t') {
context.getDocument().insertString(context.getEditor().getCaretModel().getOffset(), "\n");
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument());
}
PsiElement stepElement = context.getFile().findElementAt(context.getStartOffset()).getParent();
TemplateBuilder templateBuilder = getTemplateBuilder(stepElement, prefix);
templateBuilder.run(context.getEditor(), false);
Expand Down

0 comments on commit b626336

Please sign in to comment.