Author: mkrueger
Date: 2008-02-03 09:45:09 -0500 (Sun, 03 Feb 2008)
New Revision: 94692
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
Log:
* MonoDevelop.SourceEditor/SourceEditorView.cs: Comment/Uncomment and
Indent/Unindent commands should now work as expected.
Modified: trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
2008-02-03 14:44:28 UTC (rev 94691)
+++ trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
2008-02-03 14:45:09 UTC (rev 94692)
@@ -1,5 +1,10 @@
2008-02-03 Mike Krüger <[EMAIL PROTECTED]>
+ * MonoDevelop.SourceEditor/SourceEditorView.cs: Comment/Uncomment and
+ Indent/Unindent commands should now work as expected.
+
+2008-02-03 Mike Krüger <[EMAIL PROTECTED]>
+
* MonoDevelop.SourceEditor/SourceEditorWidget.cs,
MonoDevelop.SourceEditor/ExtendibleTextEditor.cs,
MonoDevelop.SourceEditor/SourceEditorView.cs: Implemented ISplittable.
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
2008-02-03 14:44:28 UTC (rev 94691)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
2008-02-03 14:45:09 UTC (rev 94692)
@@ -24,6 +24,7 @@
// THE SOFTWARE.
using System;
+using System.Collections.Generic;
using System.IO;
using System.Text;
using Mono.TextEditor;
@@ -661,53 +662,69 @@
public void CommentCode ()
{
- if (!this.TextEditorData.IsSomethingSelected)
- return;
+ int startLineNr =
this.TextEditorData.IsSomethingSelected ?
this.TextEditorData.Document.Splitter.GetLineNumberForOffset
(this.TextEditorData.SelectionRange.Offset) : this.TextEditorData.Caret.Line;
+ int endLineNr =
this.TextEditorData.IsSomethingSelected ?
this.TextEditorData.Document.Splitter.GetLineNumberForOffset
(this.TextEditorData.SelectionRange.EndOffset) : this.TextEditorData.Caret.Line;
StringBuilder commentTag = new
StringBuilder(Services.Languages.GetBindingPerFileName
(this.ContentName).CommentTag ?? "//");
Document.BeginAtomicUndo ();
foreach (LineSegment line in
this.TextEditorData.SelectedLines) {
this.Document.Buffer.Insert (line.Offset,
commentTag);
}
+ if (this.TextEditorData.IsSomethingSelected)
+ this.TextEditorData.SelectionStart.Column +=
commentTag.Length;
+ if (!this.TextEditorData.IsSomethingSelected
|| this.TextEditorData.SelectionEnd.Column != 0) {
+ if (this.TextEditorData.IsSomethingSelected)
+ this.TextEditorData.SelectionEnd.Column
+= commentTag.Length;
+ this.TextEditorData.Caret.PreserveSelection =
true;
+ this.TextEditorData.Caret.Column +=
commentTag.Length;
+ this.TextEditorData.Caret.PreserveSelection =
false;
+ }
Document.EndAtomicUndo ();
+ this.TextEditorData.Document.RequestUpdate (new
MultipleLineUpdate (startLineNr, endLineNr));
+ this.TextEditorData.Document.CommitDocumentUpdate ();
}
public void UncommentCode ()
{
- if (!this.TextEditorData.IsSomethingSelected)
- return;
+ int startLineNr =
this.TextEditorData.IsSomethingSelected ?
this.TextEditorData.Document.Splitter.GetLineNumberForOffset
(this.TextEditorData.SelectionRange.Offset) : this.TextEditorData.Caret.Line;
+ int endLineNr =
this.TextEditorData.IsSomethingSelected ?
this.TextEditorData.Document.Splitter.GetLineNumberForOffset
(this.TextEditorData.SelectionRange.EndOffset) : this.TextEditorData.Caret.Line;
string commentTag =
Services.Languages.GetBindingPerFileName (this.ContentName).CommentTag ?? "//";
Document.BeginAtomicUndo ();
+ int first = -1;
+ int last = 0;
foreach (LineSegment line in
this.TextEditorData.SelectedLines) {
string text = Document.Buffer.GetTextAt (line);
string trimmedText = text.TrimStart ();
+ int length = 0;
if (trimmedText.StartsWith (commentTag)) {
- text = text.Substring (0, text.Length -
trimmedText.Length) + trimmedText.Substring (commentTag.Length);
- this.Document.Buffer.Replace
(line.Offset, line.Length, new StringBuilder (text));
+ this.Document.Buffer.Remove
(line.Offset + (text.Length - trimmedText.Length), commentTag.Length);
+ length = commentTag.Length;
}
+ last = length;
+ if (first < 0)
+ first = last;
}
+ if (this.TextEditorData.IsSomethingSelected)
+ this.TextEditorData.SelectionStart.Column =
System.Math.Max (0, this.TextEditorData.SelectionStart.Column - first);
+ if (!this.TextEditorData.IsSomethingSelected
|| this.TextEditorData.SelectionEnd.Column != 0) {
+ if (this.TextEditorData.IsSomethingSelected)
+ this.TextEditorData.SelectionEnd.Column
= System.Math.Max (0, this.TextEditorData.SelectionEnd.Column - last);
+ this.TextEditorData.Caret.PreserveSelection =
true;
+ this.TextEditorData.Caret.Column =
System.Math.Max (0, this.TextEditorData.Caret.Column - last);
+ this.TextEditorData.Caret.PreserveSelection =
false;
+ }
Document.EndAtomicUndo ();
+ this.TextEditorData.Document.RequestUpdate (new
MultipleLineUpdate (startLineNr, endLineNr));
+ this.TextEditorData.Document.CommitDocumentUpdate ();
}
public void IndentSelection ()
{
- if (!this.TextEditorData.IsSomethingSelected)
- return;
- Document.BeginAtomicUndo ();
- foreach (LineSegment line in
this.TextEditorData.SelectedLines) {
- this.Document.Buffer.Insert (line.Offset, new
StringBuilder (TextEditorOptions.Options.IndentationString));
- }
- Document.EndAtomicUndo ();
+ InsertTab.IndentSelection (this.TextEditorData);
}
public void UnIndentSelection ()
{
- if (!this.TextEditorData.IsSomethingSelected)
- return;
- Document.BeginAtomicUndo ();
- foreach (LineSegment line in
this.TextEditorData.SelectedLines) {
- Mono.TextEditor.RemoveTab.RemoveTabInLine
(Document, line);
- }
- Document.EndAtomicUndo ();
+ RemoveTab.RemoveIndentSelection (this.TextEditorData);
}
#endregion
#region ISplittable
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches