void (final @NotNull Editor editor, Caret caret, DataContext dataContext) { assert caret == null : "Invocation of 'cut' operation for specific caret is not supported"; Project project = editor.getProject(); PsiFile file = project == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, null, dataContext); } return; } final SelectionModel selectionModel = editor.getSelectionModel(); CopyAction.SelectionToCopy selectionToCopy = CopyAction.prepareSelectionToCut(editor); if (selectionToCopy == null) { return; } dataContext = selectionToCopy.extendDataContext(dataContext); int start = selectionModel.getSelectionStart(); int end = selectionModel.getSelectionEnd(); final List<TextRange> selections = new ArrayList<>(); if (editor.getCaretModel().supportsMultipleCarets()) { editor.getCaretModel().runForEachCaret( __ -> 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(__ -> { TextRange range = it.next(); editor.getCaretModel().moveToOffset(range.getStartOffset()); selectionModel.removeSelection(); DocumentGuardedTextUtil.deleteString(editor.getDocument(), 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); } } }