Author: mkrueger
Date: 2008-02-12 10:08:05 -0500 (Tue, 12 Feb 2008)
New Revision: 95511

Modified:
   trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
   
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
Log:
* MonoDevelop.SourceEditor/ExtendibleTextEditor.cs: Improved auto
  insert bracket.

Modified: trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog       
2008-02-12 15:05:06 UTC (rev 95510)
+++ trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog       
2008-02-12 15:08:05 UTC (rev 95511)
@@ -1,3 +1,8 @@
+2008-02-12  Mike Krüger <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.SourceEditor/ExtendibleTextEditor.cs: Improved auto insert
+         bracket.
+
 2008-02-11  Mike Krüger <[EMAIL PROTECTED]> 
 
        * MonoDevelop.SourceEditor/SourceEditorView.cs,

Modified: 
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
        2008-02-12 15:05:06 UTC (rev 95510)
+++ 
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
        2008-02-12 15:08:05 UTC (rev 95511)
@@ -109,16 +109,29 @@
                {
                        bool result = true;
                        char ch = (char)evnt.Key;
+                       
+                       bool inStringOrComment = false;
+                       if 
(SourceEditorOptions.Options.AutoInsertMatchingBracket && (ch == '{' || ch == 
'[' || ch == '(' || ch == '"' || ch == '\'' )) {
+                               LineSegment line = Document.GetLine 
(Caret.Line);
+                               Stack<Span> stack = line.StartSpan != null ? 
new Stack<Span> (line.StartSpan) : new Stack<Span> ();
+                               SyntaxModeService.ScanSpans (Document, 
TextEditorData.Document.SyntaxMode, stack, line.Offset, Caret.Offset);
+                               foreach (Span span in stack) {
+                                       if (span.Color == "comment" || 
span.Color == "literal") {
+                                               inStringOrComment = true;
+                                               break;
+                                       }
+                               }
+                       }
                        if (extension != null) {
                                if (!extension.KeyPress (evnt.Key, evnt.State)) 
{
                                        result = base.OnKeyPressEvent (evnt);
                                }
                        } else {
-                               result = base.OnKeyPressEvent (evnt);           
                
+                               result = base.OnKeyPressEvent (evnt);
                        }
                        if (SourceEditorOptions.Options.AutoInsertTemplates && 
IsTemplateKnown ())
                                DoInsertTemplate ();
-                       if 
(SourceEditorOptions.Options.AutoInsertMatchingBracket) {
+                       if 
(SourceEditorOptions.Options.AutoInsertMatchingBracket && !inStringOrComment) {
                                switch (ch) {
                                case '{':
                                        if (extension != null) {
@@ -138,9 +151,6 @@
                                case '(':
                                        Buffer.Insert (Caret.Offset, new 
StringBuilder (")"));
                                        break;
-                               case '<':
-                                       Buffer.Insert (Caret.Offset, new 
StringBuilder (">"));
-                                       break;
                                case '\'':
                                        Buffer.Insert (Caret.Offset, new 
StringBuilder ("'"));
                                        break;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to