Java Code Examples for com.intellij.codeInsight.completion.InsertionContext#setAddCompletionChar()
The following examples show how to use
com.intellij.codeInsight.completion.InsertionContext#setAddCompletionChar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MacroCustomFunctionInsertHandler.java From intellij-latte with MIT License | 6 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { Editor editor = context.getEditor(); if (context.getCompletionChar() == '(') { context.setAddCompletionChar(false); } PsiElement element = context.getFile().findElementAt(context.getStartOffset()); if (element != null && element.getNode().getElementType() == LatteTypes.T_PHP_IDENTIFIER) { boolean notInUse = PhpUseImpl.getUseList(element) == null; if (notInUse) { if (!LatteUtil.isStringAtCaret(editor, "(")) { this.insertParenthesesCodeStyleAware(editor); } else if (LatteUtil.isStringAtCaret(editor, "()")) { editor.getCaretModel().moveCaretRelatively(2, 0, false, false, true); } else { editor.getCaretModel().moveCaretRelatively(1, 0, false, false, true); showParameterInfo(editor); } } } }
Example 2
Source File: MethodChainLookupElement.java From litho with Apache License 2.0 | 5 votes |
@Override public void handleInsert(InsertionContext context) { context.setAddCompletionChar(false); handleInsertInternal( context.getEditor(), context.getDocument(), context.getStartOffset(), context.getTailOffset(), context.getProject()); final Map<String, String> data = new HashMap<>(); data.put(EventLogger.KEY_TYPE, "required_builder"); data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_COMPLETION_TARGET_CALL); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_COMPLETION, data); }
Example 3
Source File: JsxNameCompletionProvider.java From reasonml-idea-plugin with MIT License | 5 votes |
private static void insertTagNameHandler(@NotNull Project project, @NotNull InsertionContext context, @NotNull String tagName) { char completionChar = context.getCompletionChar(); if (completionChar == ' ') { context.setAddCompletionChar(false); } Editor editor = context.getEditor(); EditorModificationUtil.insertStringAtCaret(editor, " ></" + tagName + ">"); editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 4 - tagName.length()); AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); }
Example 4
Source File: FreeExpressionCompletionProvider.java From reasonml-idea-plugin with MIT License | 5 votes |
private static void insertExpression(@NotNull InsertionContext insertionContext, @NotNull LookupElement element) { PsiElement psiElement = element.getPsiElement(); if (psiElement instanceof PsiLet) { PsiLet let = (PsiLet) psiElement; if (let.isFunction()) { insertionContext.setAddCompletionChar(false); Editor editor = insertionContext.getEditor(); EditorModificationUtil.insertStringAtCaret(editor, "()"); editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1); } } }
Example 5
Source File: JsxAttributeCompletionProvider.java From reasonml-idea-plugin with MIT License | 5 votes |
private static void insertTagAttributeHandler(@NotNull InsertionContext context) { context.setAddCompletionChar(false); Editor editor = context.getEditor(); EditorModificationUtil.insertStringAtCaret(editor, "=()"); editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1); }
Example 6
Source File: FluidViewHelperReferenceInsertHandler.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void handleInsert(InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); if (context.getCompletionChar() == '(') { context.setAddCompletionChar(false); } ViewHelper viewHelper = null; PsiElement completionParent = item.getPsiElement().getParent(); if (completionParent instanceof FluidViewHelperReference) { viewHelper = findViewHelperByReference((FluidViewHelperReference) completionParent, item); } else if(completionParent instanceof FluidBoundNamespace) { // find viewhelper } else if (completionParent instanceof FluidFieldChain) { viewHelper = findViewHelperByFieldPosition((FluidFieldChain) completionParent, item); } if (viewHelper == null) { editor.getDocument().insertString(context.getTailOffset(), "()"); return; } if (viewHelper.arguments.size() == 0) { editor.getDocument().insertString(context.getTailOffset(), "()"); return; } Template t = LiveTemplateFactory.createInlineArgumentListTemplate(viewHelper); List<ViewHelperArgument> requiredArguments = viewHelper.getRequiredArguments(); requiredArguments.forEach(a -> { int pos = requiredArguments.indexOf(a); t.addVariable("VAR" + pos, new TextExpression(""), true); }); TemplateManager.getInstance(context.getProject()).startTemplate(context.getEditor(), t); }
Example 7
Source File: CSharpTailInsertHandlerWithChar.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void handleInsert(InsertionContext context, LookupElement item) { if(context.getCompletionChar() == myEnterChar) { context.setAddCompletionChar(false); myTailType.processTail(context.getEditor(), context.getTailOffset()); } }
Example 8
Source File: PhpConstGotoCompletionProvider.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { super.handleInsert(context, lookupElement); if (context.getCompletionChar() == ':') { context.setAddCompletionChar(false); } if (!PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), SCOPE_OPERATOR)) { PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), SCOPE_OPERATOR); } PhpCompletionUtil.showCompletion(context); }
Example 9
Source File: LookupItem.java From consulo with Apache License 2.0 | 5 votes |
@Override public void handleInsert(final InsertionContext context) { final InsertHandler<? extends LookupElement> handler = getInsertHandler(); if (handler != null) { //noinspection unchecked ((InsertHandler)handler).handleInsert(context, this); } if (getTailType() != TailType.UNKNOWN && myInsertHandler == null) { context.setAddCompletionChar(false); final TailType type = handleCompletionChar(context.getEditor(), this, context.getCompletionChar()); type.processTail(context.getEditor(), context.getTailOffset()); } }
Example 10
Source File: BracesInsertHandler.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Override public void handleInsert(final InsertionContext context, final T item) { final Editor editor = context.getEditor(); final Document document = editor.getDocument(); context.commitDocument(); PsiElement element = findNextToken(context); final char completionChar = context.getCompletionChar(); final boolean putCaretInside = completionChar == '{' || placeCaretInsideParentheses(context, item); if(completionChar == '{') { context.setAddCompletionChar(false); } if(isToken(element, "{")) { int lparenthOffset = element.getTextRange().getStartOffset(); if(mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) { document.insertString(context.getTailOffset(), " "); lparenthOffset++; } if(completionChar == '{' || completionChar == '\t') { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } else { editor.getCaretModel().moveToOffset(context.getTailOffset()); } context.setTailOffset(lparenthOffset + 1); PsiElement list = element.getParent(); PsiElement last = list.getLastChild(); if(isToken(last, "}")) { int rparenthOffset = last.getTextRange().getStartOffset(); context.setTailOffset(rparenthOffset + 1); if(!putCaretInside) { for(int i = lparenthOffset + 1; i < rparenthOffset; i++) { if(!Character.isWhitespace(document.getCharsSequence().charAt(i))) { return; } } editor.getCaretModel().moveToOffset(context.getTailOffset()); } else if(mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') { editor.getCaretModel().moveToOffset(lparenthOffset + 2); } else { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + '{' + getSpace(mySpaceBetweenParentheses)); editor.getCaretModel().moveToOffset(context.getTailOffset()); } if(!myMayInsertRightParenthesis) { return; } if(context.getCompletionChar() == '{') { int tail = context.getTailOffset(); if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return; } } document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + "}"); if(!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } }
Example 11
Source File: ExpressionOrStatementInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
private void handleInsertImpl(InsertionContext context, T item, Editor editor, Document document) { PsiElement element = findNextToken(context); final char completionChar = context.getCompletionChar(); final boolean putCaretInside = completionChar == myOpenChar || placeCaretInsideParentheses(context, item); if(completionChar == myOpenChar) { context.setAddCompletionChar(false); } boolean canAddSpaceBeforePair = canAddSpaceBeforePair(context, item); if(isToken(element, myOpenChar)) { int lparenthOffset = element.getTextRange().getStartOffset(); if(canAddSpaceBeforePair && lparenthOffset == context.getTailOffset()) { document.insertString(context.getTailOffset(), " "); lparenthOffset++; } if(completionChar == myOpenChar || completionChar == '\t') { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } else { editor.getCaretModel().moveToOffset(context.getTailOffset()); } context.setTailOffset(lparenthOffset + 1); PsiElement list = element.getParent(); PsiElement last = list.getLastChild(); if(isToken(last, myCloseChar)) { int rparenthOffset = last.getTextRange().getStartOffset(); context.setTailOffset(rparenthOffset + 1); if(!putCaretInside) { for(int i = lparenthOffset + 1; i < rparenthOffset; i++) { if(!Character.isWhitespace(document.getCharsSequence().charAt(i))) { return; } } editor.getCaretModel().moveToOffset(context.getTailOffset()); } else { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), getSpace(canAddSpaceBeforePair) + myOpenChar); editor.getCaretModel().moveToOffset(context.getTailOffset()); } if(context.getCompletionChar() == myOpenChar) { int tail = context.getTailOffset(); if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return; } } document.insertString(context.getTailOffset(), String.valueOf(myCloseChar)); if(!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } }
Example 12
Source File: CSharpParenthesesInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredUIAccess @Override public void handleInsert(final InsertionContext context, final LookupElement item) { final Editor editor = context.getEditor(); final Document document = editor.getDocument(); context.commitDocument(); PsiElement element = findNextToken(context); final char completionChar = context.getCompletionChar(); final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses(); if(completionChar == '(') { context.setAddCompletionChar(false); } if(isToken(element, "(")) { int lparenthOffset = element.getTextRange().getStartOffset(); if(completionChar == '(' || completionChar == '\t') { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } else { editor.getCaretModel().moveToOffset(context.getTailOffset()); } context.setTailOffset(lparenthOffset + 1); PsiElement list = element.getParent(); PsiElement last = list.getLastChild(); if(isToken(last, ")")) { int rparenthOffset = last.getTextRange().getStartOffset(); context.setTailOffset(rparenthOffset + 1); if(!putCaretInside) { for(int i = lparenthOffset + 1; i < rparenthOffset; i++) { if(!Character.isWhitespace(document.getCharsSequence().charAt(i))) { return; } } editor.getCaretModel().moveToOffset(context.getTailOffset()); } else { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration)); editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), "" + "(" + ""); editor.getCaretModel().moveToOffset(context.getTailOffset()); } if(context.getCompletionChar() == '(') { //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType int tail = context.getTailOffset(); if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return; } } document.insertString(context.getTailOffset(), ")"); if(!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } else { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration)); } }
Example 13
Source File: LtGtInsertHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override public void handleInsert(final InsertionContext context, final T item) { final Editor editor = context.getEditor(); final Document document = editor.getDocument(); context.commitDocument(); PsiElement element = findNextToken(context); final char completionChar = context.getCompletionChar(); final boolean putCaretInside = completionChar == '<' || placeCaretInsideParentheses(context, item); if(completionChar == '<') { context.setAddCompletionChar(false); } if(isToken(element, "<")) { int lparenthOffset = element.getTextRange().getStartOffset(); if(mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) { document.insertString(context.getTailOffset(), " "); lparenthOffset++; } if(completionChar == '<' || completionChar == '\t') { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } else { editor.getCaretModel().moveToOffset(context.getTailOffset()); } context.setTailOffset(lparenthOffset + 1); PsiElement list = element.getParent(); PsiElement last = list.getLastChild(); if(isToken(last, ">")) { int rparenthOffset = last.getTextRange().getStartOffset(); context.setTailOffset(rparenthOffset + 1); if(!putCaretInside) { for(int i = lparenthOffset + 1; i < rparenthOffset; i++) { if(!Character.isWhitespace(document.getCharsSequence().charAt(i))) { return; } } editor.getCaretModel().moveToOffset(context.getTailOffset()); } else if(mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') { editor.getCaretModel().moveToOffset(lparenthOffset + 2); } else { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + "<" + getSpace(mySpaceBetweenParentheses)); editor.getCaretModel().moveToOffset(context.getTailOffset()); } if(!myMayInsertRightParenthesis) { return; } if(context.getCompletionChar() == '<') { //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType int tail = context.getTailOffset(); if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return; } } document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ">"); if(!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } }
Example 14
Source File: ParenthesesInsertHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override public void handleInsert(final InsertionContext context, final T item) { final Editor editor = context.getEditor(); final Document document = editor.getDocument(); context.commitDocument(); PsiElement lParen = findExistingLeftParenthesis(context); final char completionChar = context.getCompletionChar(); final boolean putCaretInside = completionChar == myLeftParenthesis || placeCaretInsideParentheses(context, item); if (completionChar == myLeftParenthesis) { context.setAddCompletionChar(false); } if (lParen != null) { int lparenthOffset = lParen.getTextRange().getStartOffset(); if (mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) { document.insertString(context.getTailOffset(), " "); lparenthOffset++; } if (completionChar == myLeftParenthesis || completionChar == '\t') { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } else { editor.getCaretModel().moveToOffset(context.getTailOffset()); } context.setTailOffset(lparenthOffset + 1); PsiElement list = lParen.getParent(); PsiElement last = list.getLastChild(); if (isToken(last, String.valueOf(myRightParenthesis))) { int rparenthOffset = last.getTextRange().getStartOffset(); context.setTailOffset(rparenthOffset + 1); if (!putCaretInside) { for (int i = lparenthOffset + 1; i < rparenthOffset; i++) { if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) { return; } } editor.getCaretModel().moveToOffset(context.getTailOffset()); } else if (mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') { editor.getCaretModel().moveToOffset(lparenthOffset + 2); } else { editor.getCaretModel().moveToOffset(lparenthOffset + 1); } return; } } else { document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + myLeftParenthesis + getSpace(mySpaceBetweenParentheses)); editor.getCaretModel().moveToOffset(context.getTailOffset()); } if (!myMayInsertRightParenthesis) return; if (context.getCompletionChar() == myLeftParenthesis) { //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType int tail = context.getTailOffset(); if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return; } } document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + myRightParenthesis); if (!putCaretInside) { editor.getCaretModel().moveToOffset(context.getTailOffset()); } }
Example 15
Source File: CustomLiveTemplateLookupElement.java From consulo with Apache License 2.0 | 4 votes |
@Override public void handleInsert(InsertionContext context) { context.setAddCompletionChar(false); expandTemplate(context.getEditor(), context.getFile()); }
Example 16
Source File: LiveTemplateLookupElementImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void handleInsert(InsertionContext context) { context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset()); context.setAddCompletionChar(false); TemplateManager.getInstance(context.getProject()).startTemplate(context.getEditor(), myTemplate); }