diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java index 783854a1dee1..7ee1a96035c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java @@ -83,6 +83,7 @@ public class EditorCopyPasteHelperImpl extends EditorCopyPasteHelper { if (text == null) return null; if (editor.getCaretModel().supportsMultipleCarets()) { + CaretStateTransferableData caretData = null; int caretCount = editor.getCaretModel().getCaretCount(); if (caretCount == 1 && editor.isColumnMode()) { int pastedLineCount = LineTokenizer.calcLineCount(text, true); @@ -96,13 +97,14 @@ public class EditorCopyPasteHelperImpl extends EditorCopyPasteHelper { } caretCount = editor.getCaretModel().getCaretCount(); } - CaretStateTransferableData caretData = null; - try { - caretData = content.isDataFlavorSupported(CaretStateTransferableData.FLAVOR) - ? (CaretStateTransferableData)content.getTransferData(CaretStateTransferableData.FLAVOR) : null; - } - catch (Exception e) { - LOG.error(e); + else { + try { + caretData = content.isDataFlavorSupported(CaretStateTransferableData.FLAVOR) + ? (CaretStateTransferableData)content.getTransferData(CaretStateTransferableData.FLAVOR) : null; + } + catch (Exception e) { + LOG.error(e); + } } final TextRange[] ranges = new TextRange[caretCount]; final Iterator segments = new ClipboardTextPerCaretSplitter().split(text, caretData, caretCount).iterator(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretColumnModeTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretColumnModeTest.java index a1c81695fddf..af52e69373d6 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretColumnModeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretColumnModeTest.java @@ -298,6 +298,21 @@ public class EditorMultiCaretColumnModeTest extends AbstractEditorTest { "ccccc"); } + public void testPasteOfSeveralLinesCopiedFromIdeaToASingleCaret() throws Exception { + init("a\n" + + "bbb\n" + + "ccccc"); + ((EditorEx)myEditor).setColumnMode(false); + mouse().pressAt(0, 0).dragTo(1, 1).release(); + copy(); + ((EditorEx)myEditor).setColumnMode(true); + mouse().clickAt(1, 0); + paste(); + checkResultByText("a\n" + + "abbb\n" + + "bccccc"); + } + public void testSelectToDocumentStart() throws Exception { init("line1\n" + "line2\n" +