[mono/monodevelop] d0d98a2c: Fixed 'Bug 16174 - Editor still inserting unwanted tabs'.

Mike Krüger ([email protected]) <[email protected]> Wed, 13 Nov 2013 07:09:25 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000142504b0f41-30e06037-ad78-4560-b3b0-311e4723c6cf-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/d855a1b2fcad...d0d98a2ca894

   Commit: d0d98a2ca894b5437a813cb97c0c3dd96beb6936
   Author: Mike Krüger <[email protected]> (mkrueger)
     Date: 2013-11-13 08:08:03 GMT
      URL: https://github.com/mono/monodevelop/commit/d0d98a2ca894b5437a813cb97c0c3dd96beb6936

Fixed 'Bug 16174 - Editor still inserting unwanted tabs'.

Changed paths:
  M main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs
  M main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs

Modified: main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs
===================================================================
@@ -56,7 +56,7 @@ class CSharpTextEditorIndentation : TextEditorExtension
 			}
 		}
 
-		readonly IEnumerable<string> types = MonoDevelop.Ide.DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
+		readonly IEnumerable<string> types = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
 
 		CSharpFormattingPolicy Policy {
 			get {
@@ -484,15 +484,17 @@ public override bool KeyPress (Gdk.Key key, char keyChar, Gdk.ModifierType modif
 				lastCharInserted = TranslateKeyCharForIndenter (key, keyChar, textEditorData.GetCharAt (textEditorData.Caret.Offset - 1));
 				if (lastCharInserted == '\0')
 					return retval;
-
 				using (var undo = textEditorData.OpenUndoGroup ()) {
 					SafeUpdateIndentEngine (textEditorData.Caret.Offset);
 
 					if (key == Gdk.Key.Return && modifier == Gdk.ModifierType.ControlMask) {
 						FixLineStart (textEditorData, stateTracker, textEditorData.Caret.Line + 1);
 					} else {
-						if (!(oldLine == textEditorData.Caret.Line + 1 && lastCharInserted == '\n') && (oldBufLen != textEditorData.Length || lastCharInserted != '\0'))
+						if (!(oldLine == textEditorData.Caret.Line + 1 && lastCharInserted == '\n') && (oldBufLen != textEditorData.Length || lastCharInserted != '\0')) {
 							DoPostInsertionSmartIndent (lastCharInserted, out reIndent);
+						} else {
+							reIndent = lastCharInserted == '\n';
+						}
 					}
 					//reindent the line after the insertion, if needed
 					//N.B. if the engine says we need to reindent, make sure that it's because a char was 
@@ -510,7 +512,7 @@ public override bool KeyPress (Gdk.Key key, char keyChar, Gdk.ModifierType modif
 					}
 				}
 
-				if (key != Gdk.Key.Return && (reIndent || automaticReindent)) {
+				if (reIndent || key != Gdk.Key.Return && automaticReindent) {
 					using (var undo = textEditorData.OpenUndoGroup ()) {
 						DoReSmartIndent ();
 					}
@@ -542,6 +544,10 @@ public override bool KeyPress (Gdk.Key key, char keyChar, Gdk.ModifierType modif
 			//and calls HandleCodeCompletion etc to handles completion
 			var result = base.KeyPress (key, keyChar, modifier);
 
+			if (key == Gdk.Key.Return || key == Gdk.Key.KP_Enter) {
+				DoReSmartIndent ();
+			}
+
 			CheckXmlCommentCloseTag (keyChar);
 
 			if (!skipFormatting && keyChar == '}')

Modified: main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
===================================================================
@@ -234,6 +234,45 @@ void Bar ()
 				Console.WriteLine (newText);
 			Assert.AreEqual (expected, newText);
 		}
+
+		/// <summary>
+		/// Bug 16174 - Editor still inserting unwanted tabs
+		/// </summary>
+		[Test]
+		public void TestBug16174_AutoIndent ()
+		{
+			TestViewContent content;
+
+			var ext = Setup  ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", out content);
+			ext.document.Editor.Options.IndentStyle = IndentStyle.Auto;
+			MiscActions.InsertNewLine (content.Data);
+			ext.KeyPress (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
+
+			var newText = content.Text;
+
+			var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
+			if (newText != expected)
+				Console.WriteLine (newText);
+			Assert.AreEqual (expected, newText);
+		}
+
+		[Test]
+		public void TestBug16174_VirtualIndent ()
+		{
+			TestViewContent content;
+
+			var ext = Setup  ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", out content);
+			ext.document.Editor.Options.IndentStyle = IndentStyle.Virtual;
+			MiscActions.InsertNewLine (content.Data);
+			ext.KeyPress (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
+
+			var newText = content.Text;
+
+			var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
+			if (newText != expected)
+				Console.WriteLine (newText);
+			Assert.AreEqual (expected, newText);
+		}
 	}
 }
 
_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches