public static void Left (TextEditorData data)
{
using (var undo = data.OpenUndoGroup ()) {
if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
data.ClearSelection ();
return;
}
if (data.Caret.Column > DocumentLocation.MinColumn) {
DocumentLine line = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column > line.Length + 1) {
if (data.Caret.AllowCaretBehindLineEnd) {
data.Caret.Column--;
} else {
data.Caret.Column = line.Length + 1;
}
} else {
int offset = data.Caret.Offset - 1;
foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) {
offset = System.Math.Min (offset, folding.Offset);
}
data.Caret.Offset = offset;
}
} else if (data.Caret.Line > DocumentLocation.MinLine) {
DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1);
var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1);
if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn)
nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation));
data.Caret.Location = nextLocation;
}
}
}