async void CopyData(TextEditorData data, MonoDevelop.Ide.Editor.Selection selection)
{
if (!selection.IsEmpty && data != null && data.Document != null)
{
this.docStyle = data.ColorStyle;
this.options = data.Options;
copyData = null;
switch (selection.SelectionMode)
{
case MonoDevelop.Ide.Editor.SelectionMode.Normal:
isBlockMode = false;
var segment = selection.GetSelectionRange(data);
copiedColoredChunks = await ClipboardColoredText.GetChunks(data, segment);
var pasteHandler = data.TextPasteHandler;
if (pasteHandler != null)
{
try {
copyData = pasteHandler.GetCopyData(segment.Offset, segment.Length);
} catch (Exception e) {
LoggingService.LogError("Exception while getting copy data", e);
}
}
break;
case MonoDevelop.Ide.Editor.SelectionMode.Block:
isBlockMode = true;
var visStart = data.LogicalToVisualLocation(selection.Anchor);
var visEnd = data.LogicalToVisualLocation(selection.Lead);
int startCol = System.Math.Min(visStart.Column, visEnd.Column);
int endCol = System.Math.Max(visStart.Column, visEnd.Column);
copiedColoredChunks = new List <List <ClipboardColoredText> > ();
for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++)
{
DocumentLine curLine = data.Document.GetLine(lineNr);
int col1 = curLine.GetLogicalColumn(data, startCol) - 1;
int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length);
if (col1 < col2)
{
copiedColoredChunks.Add((await ClipboardColoredText.GetChunks(data, new TextSegment(curLine.Offset + col1, col2 - col1))).First());
}
else
{
copiedColoredChunks.Add(new List <ClipboardColoredText> ());
}
}
break;
}
}
else
{
copiedColoredChunks = null;
}
}