public static void EndLineSelection(TextEditorData data)
{
int fromLine = data.MainSelection.Anchor.Line;
int toLine = data.Caret.Line;
var toSegment = data.Document.GetLine(toLine);
//flip the anchor if pivoting around the origin line
if (fromLine == toLine + 1)
{
if ((fromLine - data.MainSelection.Lead.Line) != 2)
{
var fromSegment = data.Document.GetLine(fromLine);
data.SetSelection(fromSegment.EndOffsetIncludingDelimiter, toSegment.Offset);
}
else
{
data.SetSelection(toSegment.Offset, toSegment.EndOffsetIncludingDelimiter);
}
}
//else just extend the selection else
{
int toOffset = (toLine < fromLine) ? toSegment.Offset : toSegment.EndOffsetIncludingDelimiter;
data.ExtendSelectionTo(toOffset);
}
data.Caret.PreserveSelection = false;
}