diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
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 |