public static void InsertNewLine(TextEditorData data) { if (!data.CanEditSelection) { return; } using (var undo = data.OpenUndoGroup()) { if (data.IsSomethingSelected) { var end = data.MainSelection.End; data.DeleteSelectedText(); if (end.Column == 1) { CaretMoveActions.InternalCaretMoveHome(data, true, false); return; } } switch (data.Options.IndentStyle) { case IndentStyle.None: data.InsertAtCaret(data.EolMarker); break; case IndentStyle.Auto: data.EnsureCaretIsNotVirtual(); var indent = data.Document.GetLineIndent(data.Caret.Line); data.InsertAtCaret(data.EolMarker); data.EnsureCaretIsNotVirtual(); if (data.GetLine(data.Caret.Line).Length == 0) { data.InsertAtCaret(indent); } break; case IndentStyle.Smart: if (!data.HasIndentationTracker) { goto case IndentStyle.Auto; } NewLineSmartIndent(data); break; case IndentStyle.Virtual: if (!data.HasIndentationTracker) { goto case IndentStyle.Auto; } var oldLine = data.Caret.Line; var curLine = data.GetLine(oldLine); var indentCol = data.GetVirtualIndentationColumn(data.Caret.Location); if (curLine.Length >= data.Caret.Column) { NewLineSmartIndent(data); data.FixVirtualIndentation(); data.FixVirtualIndentation(oldLine); break; } data.Insert(data.Caret.Offset, data.EolMarker); data.FixVirtualIndentation(oldLine); data.Caret.Column = indentCol; break; default: throw new ArgumentOutOfRangeException(); } } }