diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2013-08-23 09:28:15 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2013-08-23 09:28:15 +0400 |
commit | f56e30c7db64f0f9a0e9f8e94281e2872e4caeb2 (patch) | |
tree | 63dcc1b270ef8c596074a1bd1b09e754f257c336 | |
parent | 16e2727b75cfbf52c6320837b1d66ba8942d264b (diff) |
[TextEditor] Fixed selection->return key press bug.
3 files changed, 100 insertions, 10 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/CaretMoveActions.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/CaretMoveActions.cs index bb665426bb..f3e2c8bdec 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/CaretMoveActions.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/CaretMoveActions.cs @@ -218,7 +218,7 @@ namespace Mono.TextEditor return result + 1; } - static void InternalCaretMoveHome (TextEditorData data, bool firstNonWhitespace, bool hop) + internal static void InternalCaretMoveHome (TextEditorData data, bool firstNonWhitespace, bool hop) { if (!data.Caret.PreserveSelection) data.ClearSelection (); 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 a63d9a1073..6a34f3f478 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/MiscActions.cs @@ -243,8 +243,14 @@ namespace Mono.TextEditor return; using (var undo = data.OpenUndoGroup ()) { - if (data.IsSomethingSelected) + 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); diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs index c8ce7c251e..6ab5e9890b 100644 --- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs +++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs @@ -46,17 +46,92 @@ namespace MonoDevelop.CSharpBinding public class CSharpTextEditorIndentationTests : TestBase { const string eolMarker = "\n"; - TextEditorData Create (string input) + + public static TextEditorData Create (string content, ITextEditorOptions options = null) { var data = new TextEditorData (); data.Options.DefaultEolMarker = eolMarker; data.Options.IndentStyle = IndentStyle.Smart; - int idx = input.IndexOf ('$'); - if (idx > 0) - input = input.Substring (0, idx) + input.Substring (idx + 1); - data.Text = input; - if (idx > 0) - data.Caret.Offset = idx; + if (options != null) + data.Options = options; + var sb = new StringBuilder (); + int caretIndex = -1, selectionStart = -1, selectionEnd = -1; + var foldSegments = new List<FoldSegment> (); + var foldStack = new Stack<FoldSegment> (); + + for (int i = 0; i < content.Length; i++) { + var ch = content [i]; + switch (ch) { + case '$': + caretIndex = sb.Length; + break; + case '<': + if (i + 1 < content.Length) { + if (content [i + 1] == '-') { + selectionStart = sb.Length; + i++; + break; + } + } + goto default; + case '-': + if (i + 1 < content.Length) { + var next = content [i + 1]; + if (next == '>') { + selectionEnd = sb.Length; + i++; + break; + } + if (next == '[') { + var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None); + segment.IsFolded = false; + foldStack.Push (segment); + i++; + break; + } + } + goto default; + case '+': + if (i + 1 < content.Length) { + var next = content [i + 1]; + if (next == '[') { + var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None); + segment.IsFolded = true; + foldStack.Push (segment); + i++; + break; + } + } + goto default; + case ']': + if (foldStack.Count > 0) { + FoldSegment segment = foldStack.Pop (); + segment.Length = sb.Length - segment.Offset; + foldSegments.Add (segment); + break; + } + goto default; + default: + sb.Append (ch); + break; + } + } + + data.Text = sb.ToString (); + + if (caretIndex >= 0) + data.Caret.Offset = caretIndex; + if (selectionStart >= 0) { + if (caretIndex == selectionStart) { + data.SetSelection (selectionEnd, selectionStart); + } else { + data.SetSelection (selectionStart, selectionEnd); + if (caretIndex < 0) + data.Caret.Offset = selectionEnd; + } + } + if (foldSegments.Count > 0) + data.Document.UpdateFoldSegments (foldSegments); return data; } @@ -265,6 +340,15 @@ namespace MonoDevelop.CSharpBinding CheckOutput (data, @"///<summary>This is a long comment /// $ </summary>"); } + + + [Test] + public void TestEnterSelectionBehavior () + { + var data = Create ("\tfirst\n<-\tsecond\n->$\tthird"); + MiscActions.InsertNewLine (data); + + CheckOutput (data, "\tfirst\n\t$third"); + } } } - |