Search in sources :

Example 1 with OffsetMap

use of com.intellij.codeInsight.completion.OffsetMap in project intellij-community by JetBrains.

the class TemplateExpressionLookupElement method createInsertionContext.

private static InsertionContext createInsertionContext(LookupElement item, PsiFile psiFile, List<? extends LookupElement> elements, Editor editor, final char completionChar) {
    final OffsetMap offsetMap = new OffsetMap(editor.getDocument());
    final InsertionContext context = new InsertionContext(offsetMap, completionChar, elements.toArray(new LookupElement[elements.size()]), psiFile, editor, false);
    context.setTailOffset(editor.getCaretModel().getOffset());
    offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, context.getTailOffset() - item.getLookupString().length());
    offsetMap.addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, context.getTailOffset());
    offsetMap.addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, context.getTailOffset());
    return context;
}
Also used : InsertionContext(com.intellij.codeInsight.completion.InsertionContext) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) OffsetMap(com.intellij.codeInsight.completion.OffsetMap)

Aggregations

InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1 OffsetMap (com.intellij.codeInsight.completion.OffsetMap)1 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1