List of usage examples for com.intellij.openapi.editor EditorModificationUtil deleteSelectedTextForAllCarets
public static void deleteSelectedTextForAllCarets(@NotNull final Editor editor)
From source file:com.intellij.codeInsight.editorActions.TypedHandler.java
License:Apache License
@Override public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); PsiFile file;//from w ww. ja va 2s. co m if (project == null || editor.isColumnMode() || (file = PsiUtilBase.getPsiFileInEditor(editor, project)) == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, charTyped, dataContext); } return; } if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) { return; } Editor originalEditor = editor; Editor injectedEditor = injectedEditorIfCharTypedIsSignificant(charTyped, editor, file); if (injectedEditor != editor) { file = PsiDocumentManager.getInstance(project).getPsiFile(injectedEditor.getDocument()); editor = injectedEditor; } final TypedHandlerDelegate[] delegates = Extensions.getExtensions(TypedHandlerDelegate.EP_NAME); boolean handled = false; for (TypedHandlerDelegate delegate : delegates) { final TypedHandlerDelegate.Result result = delegate.checkAutoPopup(charTyped, project, editor, file); handled = result == TypedHandlerDelegate.Result.STOP; if (result != TypedHandlerDelegate.Result.CONTINUE) { break; } } if (!handled) { autoPopupCompletion(editor, charTyped, project, file); autoPopupParameterInfo(editor, charTyped, project, file); } if (!editor.isInsertMode()) { if (myOriginalHandler != null) { myOriginalHandler.execute(originalEditor, charTyped, dataContext); } return; } EditorModificationUtil.deleteSelectedTextForAllCarets(editor); FileType fileType = getFileType(file, editor); for (TypedHandlerDelegate delegate : delegates) { final TypedHandlerDelegate.Result result = delegate.beforeCharTyped(charTyped, project, editor, file, fileType); if (result == TypedHandlerDelegate.Result.STOP) { return; } if (result == TypedHandlerDelegate.Result.DEFAULT) { break; } } if (!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getCaretCount() == 1) { if (')' == charTyped || ']' == charTyped || '}' == charTyped) { if (fileType != PlainTextFileType.INSTANCE) { if (handleRParen(editor, fileType, charTyped)) return; } } else if ('"' == charTyped || '\'' == charTyped || '`' == charTyped/* || '/' == charTyped*/) { if (handleQuote(editor, charTyped, dataContext, file)) return; } } long modificationStampBeforeTyping = editor.getDocument().getModificationStamp(); if (myOriginalHandler != null) { myOriginalHandler.execute(originalEditor, charTyped, dataContext); } AutoHardWrapHandler.getInstance().wrapLineIfNecessary(editor, dataContext, modificationStampBeforeTyping); if (('(' == charTyped || '[' == charTyped || '{' == charTyped) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && !editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getCaretCount() == 1 && fileType != PlainTextFileType.INSTANCE) { handleAfterLParen(editor, fileType, charTyped); } else if ('}' == charTyped) { indentClosingBrace(project, editor); } else if (')' == charTyped) { indentClosingParenth(project, editor); } for (TypedHandlerDelegate delegate : delegates) { final TypedHandlerDelegate.Result result = delegate.charTyped(charTyped, project, editor, file); if (result == TypedHandlerDelegate.Result.STOP) { return; } if (result == TypedHandlerDelegate.Result.DEFAULT) { break; } } if ('{' == charTyped) { indentOpenedBrace(project, editor); } else if ('(' == charTyped) { indentOpenedParenth(project, editor); } }