diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-11-08 21:57:22 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-11-08 21:57:22 +0400 |
commit | 3d7a7f93a50819a5089e21bfedd332dc08d4f0ce (patch) | |
tree | 0956c7d9cd3c6d2cc7344398ea6fb182952a55be /main/src/addins/MonoDevelop.SourceEditor2 | |
parent | e51679b1a150ba564ade1510f94e9c05c4e6fa65 (diff) | |
parent | ec035e02db5d9b6e9a2c2275d3145b44264dc546 (diff) |
Merge remote-tracking branch 'origin/master' into macgtk
Conflicts:
extras/GtkSourceViewEditor/MonoDevelop.SourceEditor.addin.xml
main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs
main/src/core/Mono.Texteditor/Mono.TextEditor/GtkWorkarounds.cs
Diffstat (limited to 'main/src/addins/MonoDevelop.SourceEditor2')
5 files changed, 185 insertions, 187 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml index e06dec5121..62dbe8c026 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml @@ -7,16 +7,16 @@ description = "Provides a text editor for the MonoDevelop based on Mono.TextEditor" category = "MonoDevelop Core" flags = "Hidden" - version = "2.8.1"> + version = "2.8.2"> <Runtime> <Import assembly="MonoDevelop.SourceEditor2.dll"/> </Runtime> <Dependencies> - <Addin id="Core" version="2.8.1"/> - <Addin id="Ide" version="2.8.1"/> - <Addin id="Debugger" version="2.8.1"/> + <Addin id="Core" version="2.8.2"/> + <Addin id="Ide" version="2.8.2"/> + <Addin id="Debugger" version="2.8.2"/> </Dependencies> <!-- Extension points --> diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs index e9890837dd..19a72e118c 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs @@ -353,6 +353,7 @@ namespace MonoDevelop.SourceEditor skipChar = null; } char insertionChar = '\0'; + IDisposable undoGroup = null; if (skipChar == null && Options.AutoInsertMatchingBracket && braceIndex >= 0) { if (!inStringOrComment) { char closingBrace = closingBrackets [braceIndex]; @@ -369,7 +370,7 @@ namespace MonoDevelop.SourceEditor if (count >= 0) { startedAtomicOperation = true; - Document.BeginAtomicUndo (); + undoGroup = Document.OpenUndoGroup (); GetTextEditorData ().EnsureCaretIsNotVirtual (); int offset = Caret.Offset; @@ -382,7 +383,7 @@ namespace MonoDevelop.SourceEditor char charBefore = Document.GetCharAt (Caret.Offset - 1); if (!inString && !inComment && !inChar && ch == '"' && charBefore != '\\') { startedAtomicOperation = true; - Document.BeginAtomicUndo (); + undoGroup = Document.OpenUndoGroup (); GetTextEditorData ().EnsureCaretIsNotVirtual (); insertionChar = '"'; int offset = Caret.Offset; @@ -409,8 +410,8 @@ namespace MonoDevelop.SourceEditor HitReturn (); } } - if (startedAtomicOperation) - Document.EndAtomicUndo (); + if (undoGroup != null) + undoGroup.Dispose (); return templateInserted || result; } @@ -615,17 +616,17 @@ namespace MonoDevelop.SourceEditor return false; } - void HandleTextPaste (int insertionOffset, string text) + void HandleTextPaste (int insertionOffset, string text, int insertedChars) { if (PropertyService.Get ("OnTheFlyFormatting", false)) { var prettyPrinter = CodeFormatterService.GetFormatter (Document.MimeType); if (prettyPrinter != null && ProjectDom != null && text != null) { try { var policies = ProjectDom != null && ProjectDom.Project != null ? ProjectDom.Project.Policies : null; - string newText = prettyPrinter.FormatText (policies, Document.Text, insertionOffset, insertionOffset + text.Length); + string newText = prettyPrinter.FormatText (policies, Document.Text, insertionOffset, insertionOffset + insertedChars); if (!string.IsNullOrEmpty (newText)) { - Replace (insertionOffset, text.Length, newText); - Caret.Offset = insertionOffset + newText.Length; + int replaceResult = Replace (insertionOffset, insertedChars, newText); + Caret.Offset = insertionOffset + replaceResult; } } catch (Exception e) { LoggingService.LogError ("Error formatting pasted text", e); @@ -636,39 +637,39 @@ namespace MonoDevelop.SourceEditor internal void InsertTemplate (CodeTemplate template, MonoDevelop.Ide.Gui.Document document) { - Document.BeginAtomicUndo (); - var result = template.InsertTemplateContents (document); - var tle = new TextLinkEditMode (this, result.InsertPosition, result.TextLinks); - - if (PropertyService.Get ("OnTheFlyFormatting", false)) { - var prettyPrinter = CodeFormatterService.GetFormatter (Document.MimeType); - if (prettyPrinter != null) { - int endOffset = result.InsertPosition + result.Code.Length; - string oldText = Document.GetTextAt (result.InsertPosition, result.Code.Length); - var policies = document.Project != null ? document.Project.Policies : null; - string text = prettyPrinter.FormatText (policies, Document.Text, result.InsertPosition, endOffset); - - if (text != null) - Replace (result.InsertPosition, result.Code.Length, text); - else - //if formatting failed, just use the unformatted text - text = oldText; - - Caret.Offset = result.InsertPosition + TranslateOffset (oldText, text, Caret.Offset - result.InsertPosition); - foreach (TextLink textLink in tle.Links) { - foreach (ISegment segment in textLink.Links) { - segment.Offset = TranslateOffset (oldText, text, segment.Offset); + using (var undo = Document.OpenUndoGroup ()) { + var result = template.InsertTemplateContents (document); + var tle = new TextLinkEditMode (this, result.InsertPosition, result.TextLinks); + + if (PropertyService.Get ("OnTheFlyFormatting", false)) { + var prettyPrinter = CodeFormatterService.GetFormatter (Document.MimeType); + if (prettyPrinter != null) { + int endOffset = result.InsertPosition + result.Code.Length; + string oldText = Document.GetTextAt (result.InsertPosition, result.Code.Length); + var policies = document.Project != null ? document.Project.Policies : null; + string text = prettyPrinter.FormatText (policies, Document.Text, result.InsertPosition, endOffset); + + if (text != null) + Replace (result.InsertPosition, result.Code.Length, text); + else + //if formatting failed, just use the unformatted text + text = oldText; + + Caret.Offset = result.InsertPosition + TranslateOffset (oldText, text, Caret.Offset - result.InsertPosition); + foreach (TextLink textLink in tle.Links) { + foreach (ISegment segment in textLink.Links) { + segment.Offset = TranslateOffset (oldText, text, segment.Offset); + } } } } + + if (tle.ShouldStartTextLinkMode) { + tle.OldMode = CurrentMode; + tle.StartMode (); + CurrentMode = tle; + } } - - if (tle.ShouldStartTextLinkMode) { - tle.OldMode = CurrentMode; - tle.StartMode (); - CurrentMode = tle; - } - Document.EndAtomicUndo (); } static int TranslateOffset (string baseInput, string formattedInput, int offset) @@ -1035,11 +1036,8 @@ namespace MonoDevelop.SourceEditor [CommandHandler (MonoDevelop.Ide.Commands.EditCommands.JoinWithNextLine)] internal void JoinLines () { - try { - Document.BeginAtomicUndo (); + using (var undo = Document.OpenUndoGroup ()) { RunAction (Mono.TextEditor.Vi.ViActions.Join); - } finally { - Document.EndAtomicUndo (); } } diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs index 8f3534417a..48bb35ccd6 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs @@ -103,6 +103,8 @@ namespace MonoDevelop.SourceEditor cr.Stroke (); int errorCounterWidth = 0; + marker.EnsureLayoutCreated (base.Editor); + if (marker.Errors.Count > 1) { double rY = y + Editor.LineHeight / 6; int ew, eh; @@ -127,7 +129,6 @@ namespace MonoDevelop.SourceEditor } cr.Color = new Cairo.Color (0, 0, 0); - marker.EnsureLayoutCreated (base.Editor); int layoutWidth, layoutHeight; marker.Layouts [0].Layout.GetPixelSize (out layoutWidth, out layoutHeight); diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs index 03aeb05ac3..1f90b6915d 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs @@ -257,20 +257,20 @@ namespace MonoDevelop.SourceEditor void HandleTaskServiceJumpedToTask (object sender, TaskEventArgs e) { - Task task = e.Tasks.FirstOrDefault (); + var task = e.Tasks != null ? e.Tasks.FirstOrDefault () : null; var doc = Document; if (task == null || doc == null || task.FileName != doc.FileName || this.TextEditor == null) return; - LineSegment lineSegment = doc.GetLine (task.Line); + var lineSegment = doc.GetLine (task.Line); if (lineSegment == null) return; - MessageBubbleTextMarker marker = (MessageBubbleTextMarker)lineSegment.Markers.FirstOrDefault (m => m is MessageBubbleTextMarker); + var marker = (MessageBubbleTextMarker)lineSegment.Markers.FirstOrDefault (m => m is MessageBubbleTextMarker); if (marker == null) return; marker.SetPrimaryError (task.Description); - if (TextEditor.IsComposited) { + if (TextEditor != null && TextEditor.IsComposited) { if (messageBubbleHighlightPopupWindow != null) messageBubbleHighlightPopupWindow.Destroy (); messageBubbleHighlightPopupWindow = new MessageBubbleHighlightPopupWindow (this, marker); @@ -307,31 +307,31 @@ namespace MonoDevelop.SourceEditor DisposeErrorMarkers (); // disposes messageBubbleCache as well. if (IdeApp.Preferences.ShowMessageBubbles == ShowMessageBubbles.Never) return; - widget.Document.BeginAtomicUndo (); - if (messageBubbleCache != null) - messageBubbleCache.Dispose (); - messageBubbleCache = new MessageBubbleCache (widget.TextEditor); - - foreach (Task task in tasks) { - if (task.Severity == TaskSeverity.Error || task.Severity == TaskSeverity.Warning) { - if (IdeApp.Preferences.ShowMessageBubbles == ShowMessageBubbles.ForErrors && task.Severity == TaskSeverity.Warning) - continue; - LineSegment lineSegment = widget.Document.GetLine (task.Line); - if (lineSegment == null) - continue; - var marker = currentErrorMarkers.FirstOrDefault (m => m.LineSegment == lineSegment); - if (marker != null) { - marker.AddError (task.Severity == TaskSeverity.Error, task.Description); - continue; + using (var undo = Document.OpenUndoGroup ()) { + if (messageBubbleCache != null) + messageBubbleCache.Dispose (); + messageBubbleCache = new MessageBubbleCache (widget.TextEditor); + + foreach (Task task in tasks) { + if (task.Severity == TaskSeverity.Error || task.Severity == TaskSeverity.Warning) { + if (IdeApp.Preferences.ShowMessageBubbles == ShowMessageBubbles.ForErrors && task.Severity == TaskSeverity.Warning) + continue; + LineSegment lineSegment = widget.Document.GetLine (task.Line); + if (lineSegment == null) + continue; + var marker = currentErrorMarkers.FirstOrDefault (m => m.LineSegment == lineSegment); + if (marker != null) { + marker.AddError (task.Severity == TaskSeverity.Error, task.Description); + continue; + } + MessageBubbleTextMarker errorTextMarker = new MessageBubbleTextMarker (messageBubbleCache, task, lineSegment, task.Severity == TaskSeverity.Error, task.Description); + currentErrorMarkers.Add (errorTextMarker); + + errorTextMarker.IsVisible = !IdeApp.Preferences.DefaultHideMessageBubbles; + widget.Document.AddMarker (lineSegment, errorTextMarker, false); } - MessageBubbleTextMarker errorTextMarker = new MessageBubbleTextMarker (messageBubbleCache, task, lineSegment, task.Severity == TaskSeverity.Error, task.Description); - currentErrorMarkers.Add (errorTextMarker); - - errorTextMarker.IsVisible = !IdeApp.Preferences.DefaultHideMessageBubbles; - widget.Document.AddMarker (lineSegment, errorTextMarker, false); } } - widget.Document.EndAtomicUndo (); widget.TextEditor.QueueDraw (); } @@ -386,10 +386,10 @@ namespace MonoDevelop.SourceEditor if (PropertyService.Get ("AutoFormatDocumentOnSave", false)) { var formatter = CodeFormatterService.GetFormatter (Document.MimeType); if (formatter != null && formatter.SupportsOnTheFlyFormatting) { - TextEditor.Document.BeginAtomicUndo (); - var policies = Project != null ? Project.Policies : null; - formatter.OnTheFlyFormat (policies, TextEditor.GetTextEditorData (), 0, Document.Length); - TextEditor.Document.EndAtomicUndo (); + using (var undo = TextEditor.OpenUndoGroup ()) { + var policies = Project != null ? Project.Policies : null; + formatter.OnTheFlyFormat (policies, TextEditor.GetTextEditorData (), 0, Document.Length); + } } } @@ -1131,15 +1131,12 @@ namespace MonoDevelop.SourceEditor this.Document.Redo (); } - public void BeginAtomicUndo () - { - this.Document.BeginAtomicUndo (); - } - public void EndAtomicUndo () + + public IDisposable OpenUndoGroup () { - this.Document.EndAtomicUndo (); + return Document.OpenUndoGroup (); } - + public string SelectedText { get { return TextEditor.IsSomethingSelected ? Document.GetTextAt (TextEditor.SelectionRange) : ""; @@ -1490,26 +1487,26 @@ namespace MonoDevelop.SourceEditor triggerOffset += data.EnsureCaretIsNotVirtual (); if (blockMode) { - data.Document.BeginAtomicUndo (); + using (var undo = data.OpenUndoGroup ()) { - int minLine = data.MainSelection.MinLine; - int maxLine = data.MainSelection.MaxLine; - int column = triggerOffset - data.Document.GetLineByOffset (triggerOffset).Offset; - for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) { - LineSegment lineSegment = data.Document.GetLine (lineNumber); - if (lineSegment == null) - continue; - int offset = lineSegment.Offset + column; - data.Replace (offset, length, complete_word); + int minLine = data.MainSelection.MinLine; + int maxLine = data.MainSelection.MaxLine; + int column = triggerOffset - data.Document.GetLineByOffset (triggerOffset).Offset; + for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) { + LineSegment lineSegment = data.Document.GetLine (lineNumber); + if (lineSegment == null) + continue; + int offset = lineSegment.Offset + column; + data.Replace (offset, length, complete_word); + } + data.Caret.Offset = triggerOffset + idx; + int minColumn = System.Math.Min (data.MainSelection.Anchor.Column, data.MainSelection.Lead.Column); + data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, minColumn); + data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, TextEditor.Caret.Column); + + data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine); + data.Caret.PreserveSelection = false; } - data.Caret.Offset = triggerOffset + idx; - int minColumn = System.Math.Min (data.MainSelection.Anchor.Column, data.MainSelection.Lead.Column); - data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, minColumn); - data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, TextEditor.Caret.Column); - - data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine); - data.Caret.PreserveSelection = false; - data.Document.EndAtomicUndo (); } else { data.Replace (triggerOffset, length, complete_word); data.Caret.Offset = triggerOffset + idx; @@ -1909,12 +1906,12 @@ namespace MonoDevelop.SourceEditor var policies = Project != null ? Project.Policies : null; var editorData = TextEditor.GetTextEditorData (); if (TextEditor.IsSomethingSelected) { - TextEditor.Document.BeginAtomicUndo (); - int max = TextEditor.MainSelection.MaxLine; - for (int i = TextEditor.MainSelection.MinLine; i <= max; i++) { - formatter.CorrectIndenting (policies, editorData, i); + using (var undo = TextEditor.OpenUndoGroup ()) { + int max = TextEditor.MainSelection.MaxLine; + for (int i = TextEditor.MainSelection.MinLine; i <= max; i++) { + formatter.CorrectIndenting (policies, editorData, i); + } } - TextEditor.Document.EndAtomicUndo (); } else { formatter.CorrectIndenting (policies, editorData, TextEditor.Caret.Line); } @@ -1923,15 +1920,19 @@ namespace MonoDevelop.SourceEditor [CommandHandler (TextEditorCommands.MoveBlockUp)] protected void OnMoveBlockUp () { - TextEditor.RunAction (MiscActions.MoveBlockUp); - CorrectIndenting (); + using (var undo = TextEditor.OpenUndoGroup ()) { + TextEditor.RunAction (MiscActions.MoveBlockUp); + CorrectIndenting (); + } } [CommandHandler (TextEditorCommands.MoveBlockDown)] protected void OnMoveBlockDown () { - TextEditor.RunAction (MiscActions.MoveBlockDown); - CorrectIndenting (); + using (var undo = TextEditor.OpenUndoGroup ()) { + TextEditor.RunAction (MiscActions.MoveBlockDown); + CorrectIndenting (); + } } [CommandUpdateHandler (TextEditorCommands.ToggleBlockSelectionMode)] diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs index a24146f893..3882d1c556 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs @@ -1380,34 +1380,33 @@ namespace MonoDevelop.SourceEditor string blockStart = blockStarts[0]; string blockEnd = blockEnds[0]; - Document.BeginAtomicUndo (); - LineSegment startLine; - LineSegment endLine; - - if (TextEditor.IsSomethingSelected) { - startLine = Document.GetLineByOffset (textEditor.SelectionRange.Offset); - endLine = Document.GetLineByOffset (textEditor.SelectionRange.EndOffset); - } else { - startLine = endLine = Document.GetLine (textEditor.Caret.Line); - } - string startLineText = Document.GetTextAt (startLine.Offset, startLine.EditableLength); - string endLineText = Document.GetTextAt (endLine.Offset, endLine.EditableLength); - if (startLineText.StartsWith (blockStart) && endLineText.EndsWith (blockEnd)) { - textEditor.Remove (endLine.Offset + endLine.EditableLength - blockEnd.Length, blockEnd.Length); - textEditor.Remove (startLine.Offset, blockStart.Length); + using (var undo = Document.OpenUndoGroup ()) { + LineSegment startLine; + LineSegment endLine; + if (TextEditor.IsSomethingSelected) { - TextEditor.SelectionAnchor -= blockEnd.Length; + startLine = Document.GetLineByOffset (textEditor.SelectionRange.Offset); + endLine = Document.GetLineByOffset (textEditor.SelectionRange.EndOffset); + } else { + startLine = endLine = Document.GetLine (textEditor.Caret.Line); } - } else { - textEditor.Insert (endLine.Offset + endLine.EditableLength, blockEnd); - textEditor.Insert (startLine.Offset, blockStart); - if (TextEditor.IsSomethingSelected) { - TextEditor.SelectionAnchor += blockEnd.Length; + string startLineText = Document.GetTextAt (startLine.Offset, startLine.EditableLength); + string endLineText = Document.GetTextAt (endLine.Offset, endLine.EditableLength); + if (startLineText.StartsWith (blockStart) && endLineText.EndsWith (blockEnd)) { + textEditor.Remove (endLine.Offset + endLine.EditableLength - blockEnd.Length, blockEnd.Length); + textEditor.Remove (startLine.Offset, blockStart.Length); + if (TextEditor.IsSomethingSelected) { + TextEditor.SelectionAnchor -= blockEnd.Length; + } + } else { + textEditor.Insert (endLine.Offset + endLine.EditableLength, blockEnd); + textEditor.Insert (startLine.Offset, blockStart); + if (TextEditor.IsSomethingSelected) { + TextEditor.SelectionAnchor += blockEnd.Length; + } + } - } - - Document.EndAtomicUndo (); } public void ToggleCodeComment () @@ -1470,32 +1469,32 @@ namespace MonoDevelop.SourceEditor LineSegment anchorLine = TextEditor.IsSomethingSelected ? TextEditor.Document.GetLineByOffset (TextEditor.SelectionAnchor) : null; int anchorColumn = TextEditor.IsSomethingSelected ? TextEditor.SelectionAnchor - anchorLine.Offset : -1; - Document.BeginAtomicUndo (); - foreach (LineSegment line in TextEditor.SelectedLines) { - TextEditor.Insert (line.Offset, commentTag); - } - if (TextEditor.IsSomethingSelected) { - if (TextEditor.SelectionAnchor < TextEditor.Caret.Offset) { - if (anchorColumn != 0) - TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, TextEditor.SelectionAnchor + commentTag.Length)); - } else { - if (anchorColumn != 0) { - TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, anchorLine.Offset + anchorColumn + commentTag.Length)); + using (var undo = Document.OpenUndoGroup ()) { + foreach (LineSegment line in TextEditor.SelectedLines) { + TextEditor.Insert (line.Offset, commentTag); + } + if (TextEditor.IsSomethingSelected) { + if (TextEditor.SelectionAnchor < TextEditor.Caret.Offset) { + if (anchorColumn != 0) + TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, TextEditor.SelectionAnchor + commentTag.Length)); } else { -// TextEditor.SelectionAnchor = anchorLine.Offset; + if (anchorColumn != 0) { + TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, anchorLine.Offset + anchorColumn + commentTag.Length)); + } else { + // TextEditor.SelectionAnchor = anchorLine.Offset; + } } } + + if (TextEditor.Caret.Column != 0) { + TextEditor.Caret.PreserveSelection = true; + TextEditor.Caret.Column += commentTag.Length; + TextEditor.Caret.PreserveSelection = false; + } + + if (TextEditor.IsSomethingSelected) + TextEditor.ExtendSelectionTo (TextEditor.Caret.Offset); } - - if (TextEditor.Caret.Column != 0) { - TextEditor.Caret.PreserveSelection = true; - TextEditor.Caret.Column += commentTag.Length; - TextEditor.Caret.PreserveSelection = false; - } - - if (TextEditor.IsSomethingSelected) - TextEditor.ExtendSelectionTo (TextEditor.Caret.Offset); - Document.EndAtomicUndo (); Document.CommitMultipleLineUpdate (startLineNr, endLineNr); } @@ -1508,40 +1507,39 @@ namespace MonoDevelop.SourceEditor LineSegment anchorLine = TextEditor.IsSomethingSelected ? TextEditor.Document.GetLineByOffset (TextEditor.SelectionAnchor) : null; int anchorColumn = TextEditor.IsSomethingSelected ? TextEditor.SelectionAnchor - anchorLine.Offset : -1; - Document.BeginAtomicUndo (); - int first = -1; - int last = 0; - foreach (LineSegment line in TextEditor.SelectedLines) { - string text = Document.GetTextAt (line); - string trimmedText = text.TrimStart (); - int length = 0; - if (trimmedText.StartsWith (commentTag)) { - TextEditor.Remove (line.Offset + (text.Length - trimmedText.Length), commentTag.Length); - length = commentTag.Length; + using (var undo = Document.OpenUndoGroup ()) { + int first = -1; + int last = 0; + foreach (LineSegment line in TextEditor.SelectedLines) { + string text = Document.GetTextAt (line); + string trimmedText = text.TrimStart (); + int length = 0; + if (trimmedText.StartsWith (commentTag)) { + TextEditor.Remove (line.Offset + (text.Length - trimmedText.Length), commentTag.Length); + length = commentTag.Length; + } + last = length; + if (first < 0) + first = last; } - last = length; - if (first < 0) - first = last; - } - - if (TextEditor.IsSomethingSelected) { - if (TextEditor.SelectionAnchor < TextEditor.Caret.Offset) { - TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, TextEditor.SelectionAnchor - first)); - } else { - TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, anchorLine.Offset + anchorColumn - last)); + + if (TextEditor.IsSomethingSelected) { + if (TextEditor.SelectionAnchor < TextEditor.Caret.Offset) { + TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, TextEditor.SelectionAnchor - first)); + } else { + TextEditor.SelectionAnchor = System.Math.Min (anchorLine.Offset + anchorLine.EditableLength, System.Math.Max (anchorLine.Offset, anchorLine.Offset + anchorColumn - last)); + } } + + if (TextEditor.Caret.Column != DocumentLocation.MinColumn) { + TextEditor.Caret.PreserveSelection = true; + TextEditor.Caret.Column = System.Math.Max (DocumentLocation.MinColumn, TextEditor.Caret.Column - last); + TextEditor.Caret.PreserveSelection = false; + } + + if (TextEditor.IsSomethingSelected) + TextEditor.ExtendSelectionTo (TextEditor.Caret.Offset); } - - if (TextEditor.Caret.Column != DocumentLocation.MinColumn) { - TextEditor.Caret.PreserveSelection = true; - TextEditor.Caret.Column = System.Math.Max (DocumentLocation.MinColumn, TextEditor.Caret.Column - last); - TextEditor.Caret.PreserveSelection = false; - } - - if (TextEditor.IsSomethingSelected) - TextEditor.ExtendSelectionTo (TextEditor.Caret.Offset); - - Document.EndAtomicUndo (); Document.CommitMultipleLineUpdate (startLineNr, endLineNr); } |