[Monodevelop-patches-list] r1443 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: . Gui
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Mon Apr 12 02:09:50 EDT 2004
Author: nickd
Date: 2004-04-12 02:09:50 -0400 (Mon, 12 Apr 2004)
New Revision: 1443
Modified:
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
Log:
2004-04-12 Nick Drochak <ndrochak at gol.com>
* Gui/SourceEditorView.cs: Use white space already on the line to
indent the 2nd and following lines of an inserted template.
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog 2004-04-12 03:03:38 UTC (rev 1442)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog 2004-04-12 06:09:50 UTC (rev 1443)
@@ -1,3 +1,8 @@
+2004-04-12 Nick Drochak <ndrochak at gol.com>
+
+ * Gui/SourceEditorView.cs: Use white space already on the line to
+ indent the 2nd and following lines of an inserted template.
+
2004-04-10 Todd Berman <tberman at sevenl.net>
* Gui/SourceEditorView.cs: fix logic bug.
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-04-12 03:03:38 UTC (rev 1442)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-04-12 06:09:50 UTC (rev 1443)
@@ -293,15 +293,27 @@
return start;
}
-
+ public string GetLeadingWhiteSpace (int line) {
+ string lineText = ((IFormattableDocument)this).GetLineAsString (line);
+ int index = 0;
+ while (index < lineText.Length && Char.IsWhiteSpace (lineText[index])) {
+ index++;
+ }
+ return index > 0 ? lineText.Substring (0, index) : "";
+ }
+
public void InsertTemplate (CodeTemplate template)
{
- int newCaretOffset = buf.GetIterAtMark (buf.InsertMark).Offset;
+ TextIter iter = buf.GetIterAtMark (buf.InsertMark);
+ int newCaretOffset = iter.Offset;
string word = GetWordBeforeCaret ().Trim ();
-
+ int beginLine = iter.Line;
+ int endLine = beginLine;
if (word.Length > 0)
newCaretOffset = DeleteWordBeforeCaret ();
+ string leadingWhiteSpace = GetLeadingWhiteSpace (beginLine);
+
int finalCaretOffset = newCaretOffset;
for (int i =0; i < template.Text.Length; ++i) {
@@ -318,6 +330,7 @@
case '\n':
buf.InsertAtCursor ('\n'.ToString ());
newCaretOffset++;
+ endLine++;
break;
default:
buf.InsertAtCursor (template.Text[i].ToString ());
@@ -326,6 +339,10 @@
}
}
+ if (endLine > beginLine) {
+ IndentLines (beginLine+1, endLine, leadingWhiteSpace);
+ }
+
buf.PlaceCursor (buf.GetIterAtOffset (finalCaretOffset));
}
@@ -369,8 +386,11 @@
void IndentLines (int y0, int y1)
{
- string indent = InsertSpacesInsteadOfTabs ? new string (' ', (int) TabsWidth) : "\t";
-
+ IndentLines (y0, y1, InsertSpacesInsteadOfTabs ? new string (' ', (int) TabsWidth) : "\t");
+ }
+
+ void IndentLines (int y0, int y1, string indent)
+ {
for (int l = y0; l <= y1; l ++)
Buffer.Insert (Buffer.GetIterAtLine (l), indent);
}
More information about the Monodevelop-patches-list
mailing list