[mono/monodevelop] [2 commits] ba9ba3ee: Fixed 'Bug 15335 - In a multiline comment, pressing Enter jumps way ahead'

Mike Krüger ([email protected]) <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141b5bacdbb-eba71474-2624-4ced-9a32-d2277a60c2a2-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/ef18fb96dad5...7a159de82c68

   Commit: ba9ba3ee2b94fe4e0d7e7bb013353b088ab44eb4
   Author: Mike Krüger <[email protected]> (mkrueger)
     Date: 2013-10-14 06:18:57 GMT
      URL: https://github.com/mono/monodevelop/commit/ba9ba3ee2b94fe4e0d7e7bb013353b088ab44eb4

Fixed 'Bug 15335 - In a multiline comment, pressing Enter jumps way ahead'

Changed paths:
  M main/external/nrefactory
  M main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs

Modified: main/external/nrefactory
===================================================================
@@ -1 +1 @@
-Subproject commit 0bbf46a3b1a78eb20267e4be90f3cb5e457f09a6
+Subproject commit 37f7f49e89db32b4fa5eab0a6a7bdea54154e313

Modified: main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs
===================================================================
@@ -358,5 +358,18 @@ public void TestEnterSelectionBehavior ()
 
 			CheckOutput (data, "\tfirst\n\t$third");
 		}
+
+
+		/// <summary>
+		/// Bug 15335 - In a multiline comment, pressing Enter jumps way ahead
+		/// </summary>
+		[Test]
+		public void TestBug15335 ()
+		{
+			var data = Create ("namespace Foo\n{\n\tpublic class Bar\n\t{\n\t\tvoid Test()\r\n\t\t{\r\n\t\t\t/* foo$\n\t\t}\n\t}\n}\n");
+			MiscActions.InsertNewLine (data);
+
+			CheckOutput (data, "namespace aFoo\n{\n\tpublic class Bar\n\t{\n\t\tvoid Test()\r\n\t\t{\r\n\t\t\t/* foo\n\t\t\t * $\n\t\t}\n\t}\n}\n");
+		}
 	}
 }

   Commit: 7a159de82c689945b5eb8cc78078d07180bfbdaf
   Author: Mike Krüger <[email protected]> (mkrueger)
     Date: 2013-10-14 06:47:36 GMT
      URL: https://github.com/mono/monodevelop/commit/7a159de82c689945b5eb8cc78078d07180bfbdaf

[SourceEditor] Editor now detects mixed line endings as well.

Changed paths:
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/ClipboardActions.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor/Document/ILineSplitter.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor/Document/LineSplitter.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor/Document/PrimitiveLineSplitter.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs
===================================================================
@@ -861,6 +861,8 @@ public void ShowFileChangedWarning (bool multiple)
 		internal bool UseIncorrectMarkers { get; set; }
 		internal bool HasIncorrectEolMarker {
 			get {
+				if (Document.HasLineEndingMismatchOnTextSet)
+					return true;
 				string eol = DetectedEolMarker;
 				if (eol == null)
 					return false;
@@ -869,6 +871,8 @@ public void ShowFileChangedWarning (bool multiple)
 		}
 		string DetectedEolMarker {
 			get {
+				if (Document.HasLineEndingMismatchOnTextSet)
+					return "?";
 				if (textEditor.IsDisposed) {
 					LoggingService.LogWarning ("SourceEditorWidget.cs: HasIncorrectEolMarker was called on disposed source editor widget." + Environment.NewLine + Environment.StackTrace);
 					return null;
@@ -924,6 +928,7 @@ internal void ConvertLineEndings ()
 			}
 			view.StoreSettings ();
 			view.ReplaceContent (Document.FileName, newText.ToString (), null);
+			Document.HasLineEndingMismatchOnTextSet = false;
 			view.LoadSettings ();
 		}
 
@@ -936,6 +941,8 @@ static string GetEolString (string detectedEol)
 				return "Windows";
 			case "\r":
 				return "Mac";
+			case "?":
+				return "mixed";
 			}
 			return "Unknown";
 		}

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/ClipboardActions.cs
===================================================================
@@ -312,7 +312,7 @@ static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSel
 									if (delimiter.IsInvalid)
 										break;
 
-									int delimiterEndOffset = delimiter.Offset + delimiter.Length;
+									int delimiterEndOffset = delimiter.EndOffset;
 									lines.Add (text.Substring (offset, delimiter.Offset - offset));
 									offset = delimiterEndOffset;
 								}

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor/Document/ILineSplitter.cs
===================================================================
@@ -8,6 +8,14 @@ public interface ILineSplitter
 	{
 		int Count { get; }
 
+		/// <summary>
+		/// True if during initialization a line ending mismatch was encountered.
+		/// </summary>
+		bool LineEndingMismatch {
+			get;
+			set;
+		}
+
 		IEnumerable<DocumentLine> Lines { get; }
 
 		void Clear ();

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor/Document/LineSplitter.cs
===================================================================
@@ -131,23 +131,31 @@ public void TextRemove (int offset, int length)
 			ChangeLength (startNode, startNode.LengthIncludingDelimiter - charsRemoved + charsLeft, endNode.DelimiterLength);
 		}
 
+		public bool LineEndingMismatch {
+			get;
+			set;
+		}
+
 		//bool inInit;
 		public void Initalize (string text)
 		{
+			LineEndingMismatch = false;
 			Clear ();
 			if (string.IsNullOrEmpty (text))
 				return;
 			var nodes = new List<TreeNode> ();
 
+			var delimiterType = UnicodeNewline.Unknown;
 			int offset = 0;
 			while (true) {
 				var delimiter = NextDelimiter (text, offset);
 				if (delimiter.IsInvalid)
 					break;
-
 				int delimiterEndOffset = delimiter.Offset + delimiter.Length;
 				var newLine = new TreeNode (delimiterEndOffset - offset, delimiter.Length);
 				nodes.Add (newLine);
+				if (offset > 0 && delimiterType != delimiter.UnicodeNewline)
+					LineEndingMismatch = true;
 				offset = delimiterEndOffset;
 			}
 			var lastLine = new TreeNode (text.Length - offset, 0);
@@ -219,7 +227,13 @@ internal struct Delimiter
 			public static readonly Delimiter Invalid = new Delimiter (-1, 0);
 
 			public readonly int Offset;
-			public readonly int Length;
+			public readonly UnicodeNewline UnicodeNewline;
+
+			public int Length {
+				get {
+					return UnicodeNewline == UnicodeNewline.CRLF ? 2 : 1;
+				}
+			}
 
 			public int EndOffset {
 				get { return Offset + Length; }
@@ -231,10 +245,10 @@ internal struct Delimiter
 				}
 			}
 
-			public Delimiter (int offset, int length)
+			public Delimiter (int offset, UnicodeNewline unicodeNewline)
 			{
 				Offset = offset;
-				Length = length;
+				UnicodeNewline = unicodeNewline;
 			}
 		}
 
@@ -243,12 +257,13 @@ static unsafe internal Delimiter NextDelimiter (string text, int offset)
 			fixed (char* start = text) {
 				char* p = start + offset;
 				char* endPtr = start + text.Length;
+
 				while (p < endPtr) {
 					char* nextp = p + 1;
 					char nextChar = nextp < endPtr ? *nextp : '\0';
-					var nl = NewLine.GetDelimiterLength (*p, nextChar);
-					if (nl > 0)
-						return new Delimiter ((int)(p - start), nl);
+					var type = NewLine.GetDelimiterType (*p, nextChar);
+					if (type != UnicodeNewline.Unknown)
+						return new Delimiter ((int)(p - start), type);
 					p++;
 				}
 				return Delimiter.Invalid;

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor/Document/PrimitiveLineSplitter.cs
===================================================================
@@ -45,6 +45,11 @@ public PrimitiveLineSegment (PrimitiveLineSplitter splitter, int lineNumber, int
 			}
 		}
 
+		public bool LineEndingMismatch {
+			get;
+			set;
+		}
+
 		public int Count {
 			get { return delimiters.Count + 1; }
 		}

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs
===================================================================
@@ -125,6 +125,15 @@ protected virtual void OnSyntaxModeChanged (Mono.TextEditor.SyntaxModeChangeEven
 			get;
 			set;
 		}
+
+		public bool HasLineEndingMismatchOnTextSet {
+			get {
+				return splitter.LineEndingMismatch;
+			}
+			set {
+				splitter.LineEndingMismatch = value;
+			}
+		}
 		
 		protected TextDocument (IBuffer buffer,ILineSplitter splitter)
 		{
_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.