Java 类com.intellij.openapi.editor.actions.CopyAction 实例源码

项目:tools-idea    文件:CutHandler.java   
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getContentComponent()));
  if (project == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection() && !selectionModel.hasBlockSelection()) {
    if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) {
      return;
    }
    selectionModel.selectLineAtCaret();
    if (!selectionModel.hasSelection()) return;
  }

  int start = selectionModel.getSelectionStart();
  int end = selectionModel.getSelectionEnd();

  EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_COPY).execute(editor, dataContext);

  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);
  }
}