boolean (final JComponent comp, final Transferable t) { final EditorImpl editor = (EditorImpl)getEditor(comp); final int caretOffset = editor.getCaretModel().getOffset(); if (myDraggedRange != null && myDraggedRange.getStartOffset() <= caretOffset && caretOffset < myDraggedRange.getEndOffset()) { return false; } if (myDraggedRange != null) { editor.getCaretModel().moveToOffset(editor.mySavedCaretOffsetForDNDUndoHack); } CommandProcessor.getInstance().executeCommand(editor.myProject, new Runnable() { public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { final int offset; editor.getSelectionModel().removeSelection(); if (myDraggedRange != null) { editor.getCaretModel().moveToOffset(caretOffset); offset = caretOffset; } else { offset = editor.getCaretModel().getOffset(); } if (editor.getDocument().getRangeGuard(offset, offset) != null) return; EditorActionHandler pasteHandler = EditorActionManager.getInstance().getActionHandler( IdeActions.ACTION_EDITOR_PASTE); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable backup = clipboard.getContents(this); ClipboardOwner clipboardOwner = new ClipboardOwner() { public void lostOwnership(Clipboard clipboard, Transferable contents) { } }; clipboard.setContents(t, clipboardOwner); editor.putUserData(LAST_PASTED_REGION, null); pasteHandler.execute(editor, editor.getDataContext()); clipboard.setContents(backup, clipboardOwner); TextRange range = editor.getUserData(LAST_PASTED_REGION); if (range != null) { editor.getCaretModel().moveToOffset(range.getStartOffset()); editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); } } catch (Exception exception) { LOG.error(exception); } } }); } }, "Paste", DND_COMMAND_KEY); return true; }