List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_COPY
String ACTION_EDITOR_COPY
To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_COPY.
Click Source Link
From source file:com.intellij.codeInsight.editorActions.CutHandler.java
License:Apache License
@Override public void executeWriteAction(final Editor editor, Caret caret, DataContext dataContext) { assert caret == null : "Invocation of 'cut' operation for specific caret is not supported"; Project project = CommonDataKeys.PROJECT .getData(DataManager.getInstance().getDataContext(editor.getContentComponent())); if (project == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, null, dataContext); }//from ww w. j a va2s.c o m return; } final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, null, dataContext); } return; } final SelectionModel selectionModel = editor.getSelectionModel(); if (!selectionModel.hasSelection(true) && !selectionModel.hasBlockSelection()) { if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) { return; } editor.getCaretModel().runForEachCaret(new CaretAction() { @Override public void perform(Caret caret) { selectionModel.selectLineAtCaret(); } }); if (!selectionModel.hasSelection(true)) return; } int start = selectionModel.getSelectionStart(); int end = selectionModel.getSelectionEnd(); final List<TextRange> selections = new ArrayList<TextRange>(); if (editor.getCaretModel().supportsMultipleCarets()) { editor.getCaretModel().runForEachCaret(new CaretAction() { @Override public void perform(Caret caret) { selections.add( new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())); } }); } EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_COPY).execute(editor, null, dataContext); if (editor.getCaretModel().supportsMultipleCarets()) { Collections.reverse(selections); final Iterator<TextRange> it = selections.iterator(); editor.getCaretModel().runForEachCaret(new CaretAction() { @Override public void perform(Caret caret) { TextRange range = it.next(); editor.getCaretModel().moveToOffset(range.getStartOffset()); selectionModel.removeSelection(); editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset()); } }); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } else { if (start != end) { // There is a possible case that 'sticky selection' is active. It's automatically removed on copying then, so, we explicitly // remove the text. editor.getDocument().deleteString(start, end); } else { EditorModificationUtil.deleteSelectedText(editor); } } }
From source file:com.intellij.testFramework.LightPlatformCodeInsightTestCase.java
License:Apache License
protected static void copy() { executeAction(IdeActions.ACTION_EDITOR_COPY); }