IDEA-154425 copy-paste in column mode bug

This commit is contained in:
Dmitry Batrak
2016-04-11 14:17:59 +03:00
parent 6a73ff84ae
commit bcb6f8d2f3
2 changed files with 24 additions and 7 deletions
@@ -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<String> segments = new ClipboardTextPerCaretSplitter().split(text, caretData, caretCount).iterator();
@@ -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" +
"a<caret>bbb\n" +
"b<caret>ccccc");
}
public void testSelectToDocumentStart() throws Exception {
init("line1\n" +
"line2\n" +