Example usage for com.intellij.openapi.editor EditorModificationUtil typeInStringAtCaretHonorMultipleCarets

List of usage examples for com.intellij.openapi.editor EditorModificationUtil typeInStringAtCaretHonorMultipleCarets

Introduction

In this page you can find the example usage for com.intellij.openapi.editor EditorModificationUtil typeInStringAtCaretHonorMultipleCarets.

Prototype

public static void typeInStringAtCaretHonorMultipleCarets(final Editor editor, @NotNull final String str,
            final boolean toProcessOverwriteMode) 

Source Link

Usage

From source file:com.intellij.codeInsight.lookup.impl.LookupTypedHandler.java

License:Apache License

@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Override//from ww w.  j a  va  2  s .  c  om
public Result beforeCharTyped(final char charTyped, Project project, final Editor editor, PsiFile file,
        FileType fileType) {
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(editor);
    if (lookup == null) {
        return Result.CONTINUE;
    }

    if (charTyped == ' ' && ChooseItemAction.hasTemplatePrefix(lookup, TemplateSettings.SPACE_CHAR)) {
        return Result.CONTINUE;
    }

    final CharFilter.Result result = getLookupAction(charTyped, lookup);
    if (lookup.isLookupDisposed()) {
        return Result.CONTINUE;
    }

    if (!lookup.performGuardedChange(new Runnable() {
        @Override
        public void run() {
            EditorModificationUtil.deleteSelectedText(editor);
        }
    })) {
        return Result.STOP;
    }
    if (result == CharFilter.Result.ADD_TO_PREFIX) {
        Document document = editor.getDocument();
        long modificationStamp = document.getModificationStamp();

        if (!lookup.performGuardedChange(new Runnable() {
            @Override
            public void run() {
                EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(editor, String.valueOf(charTyped),
                        true);
            }
        })) {
            return Result.STOP;
        }
        lookup.appendPrefix(charTyped);
        if (lookup.isStartCompletionWhenNothingMatches() && lookup.getItems().isEmpty()) {
            final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService()
                    .getCurrentCompletion();
            if (completion != null) {
                completion.scheduleRestart();
            } else {
                AutoPopupController.getInstance(editor.getProject()).scheduleAutoPopup(editor);
            }
        }

        AutoHardWrapHandler.getInstance().wrapLineIfNecessary(editor,
                DataManager.getInstance().getDataContext(editor.getContentComponent()), modificationStamp);

        final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService()
                .getCurrentCompletion();
        if (completion != null) {
            completion.prefixUpdated();
        }
        return Result.STOP;
    }

    if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP && lookup.isFocused()) {
        LookupElement item = lookup.getCurrentItem();
        if (item != null) {
            if (completeTillTypedCharOccurrence(charTyped, lookup, item)) {
                return Result.STOP;
            }

            FeatureUsageTracker.getInstance()
                    .triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC);
            lookup.finishLookup(charTyped);
            return Result.STOP;
        }
    }

    lookup.hide();
    TypedHandler.autoPopupCompletion(editor, charTyped, project, file);
    return Result.CONTINUE;
}