diff options
Diffstat (limited to 'main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs')
-rw-r--r-- | main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs index 8a42f8b0a0..37b5dd2c81 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs @@ -272,9 +272,11 @@ namespace Mono.TextEditor break; case IndentStyle.Auto: data.EnsureCaretIsNotVirtual (); - var sb = new StringBuilder (data.EolMarker); - sb.Append (data.Document.GetLineIndent (data.Caret.Line)); - data.InsertAtCaret (sb.ToString ()); + 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) @@ -511,59 +513,5 @@ namespace Mono.TextEditor } } - public static void SortSelectedLines (TextEditorData data) - { - var start = data.MainSelection.Start; - var end = data.MainSelection.End; - var caret = data.Caret.Location; - - int startLine = start.Line; - int endLine = end.Line; - if (startLine == endLine) - return; - - int length = 0; - var lines = new string[endLine - startLine + 1]; - for (int i = startLine; i <= endLine; i++) { - //get lines *with* line endings - var lineText = data.GetLineText (i, true); - lines [i - startLine] = lineText; - length += lineText.Length; - } - - var linesUnsorted = new string[lines.Length]; - - Array.Sort (lines, StringComparer.Ordinal); - - bool changed = false; - for (int i = 0; i <= lines.Length; i++) { - //can't simply use reference comparison as Array.Sort is not stable - if (string.Equals (lines [i], linesUnsorted [i], StringComparison.Ordinal)) { - continue; - } - changed = true; - break; - } - if (!changed) { - return; - } - - - var sb = new StringBuilder (); - for (int i = 0; i < lines.Length; i++) { - sb.Append (lines [i]); - } - - var startOffset = data.Document.LocationToOffset (new TextLocation (startLine, 0)); - data.Replace (startOffset, length, sb.ToString ()); - - data.Caret.Location = LimitColumn (data, caret); - data.SetSelection (LimitColumn (data, start), LimitColumn (data, end)); - } - - static DocumentLocation LimitColumn (TextEditorData data, DocumentLocation loc) - { - return new DocumentLocation (loc.Line, System.Math.Min (loc.Column, data.GetLine (loc.Line).Length + 1)); - } } }
\ No newline at end of file |