List of usage examples for com.intellij.openapi.editor RawText RawText
public RawText(final String rawText)
From source file:com.intellij.codeInsight.editorActions.CopyHandler.java
License:Apache License
@Override public void doExecute(final Editor editor, Caret caret, final DataContext dataContext) { assert caret == null : "Invocation of 'copy' operation for specific caret is not supported"; final Project project = CommonDataKeys.PROJECT .getData(DataManager.getInstance().getDataContext(editor.getComponent())); if (project == null) { if (myOriginalAction != null) { myOriginalAction.execute(editor, null, dataContext); }// w ww. ja v a2s. com return; } final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { if (myOriginalAction != null) { myOriginalAction.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; editor.getCaretModel().runForEachCaret(new CaretAction() { @Override public void perform(Caret caret) { EditorActionUtil.moveCaretToLineStartIgnoringSoftWraps(editor); } }); } PsiDocumentManager.getInstance(project).commitAllDocuments(); final int[] startOffsets = selectionModel.getBlockSelectionStarts(); final int[] endOffsets = selectionModel.getBlockSelectionEnds(); List<TextBlockTransferableData> transferableDatas = new ArrayList<TextBlockTransferableData>(); for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions .getExtensions(CopyPastePostProcessor.EP_NAME)) { transferableDatas.addAll(processor.collectTransferableData(file, editor, startOffsets, endOffsets)); } String text = editor.getCaretModel().supportsMultipleCarets() ? EditorCopyPasteHelperImpl.getSelectedTextForClipboard(editor, transferableDatas) : selectionModel.getSelectedText(); String rawText = TextBlockTransferable.convertLineSeparators(text, "\n", transferableDatas); String escapedText = null; for (CopyPastePreProcessor processor : Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) { escapedText = processor.preprocessOnCopy(file, startOffsets, endOffsets, rawText); if (escapedText != null) { break; } } final Transferable transferable = new TextBlockTransferable(escapedText != null ? escapedText : rawText, transferableDatas, escapedText != null ? new RawText(rawText) : null); CopyPasteManager.getInstance().setContents(transferable); if (editor instanceof EditorEx) { EditorEx ex = (EditorEx) editor; if (ex.isStickySelection()) { ex.setStickySelection(false); } } }