示例#1
0
 public DocumentLineWrapper(Mono.TextEditor.DocumentLine line)
 {
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
     this.Line = line;
 }
 static bool IsBlankLine(Mono.TextEditor.TextDocument doc, Mono.TextEditor.DocumentLine line)
 {
     for (int i = 0; i < line.Length; i++)
     {
         if (!Char.IsWhiteSpace(doc.GetCharAt(line.Offset + i)))
         {
             return(false);
         }
     }
     return(true);
 }
示例#3
0
        public static void MoveBlockDown(TextEditorData data)
        {
            int              lineStart = data.Caret.Line;
            int              lineEnd = data.Caret.Line;
            bool             setSelection = lineStart != lineEnd;
            DocumentLocation anchor = DocumentLocation.Empty, lead = DocumentLocation.Empty;

            if (data.IsSomethingSelected)
            {
                setSelection = true;
                lineStart    = data.MainSelection.MinLine;
                lineEnd      = data.MainSelection.MaxLine;
                anchor       = data.MainSelection.Anchor;
                lead         = data.MainSelection.Lead;
            }

            if (lineStart <= 0)
            {
                return;
            }
            using (var undo = data.OpenUndoGroup()) {
                //Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
                //int relCaretOffset = data.Caret.Offset - startLine.Offset;

                Mono.TextEditor.DocumentLine nextLine = data.Document.GetLine(lineEnd + 1);
                if (nextLine == null)
                {
                    return;
                }
                string text = data.Document.GetTextAt(nextLine.Offset, nextLine.Length);

                List <TextLineMarker> prevLineMarkers = new List <TextLineMarker> (data.Document.GetMarkers(nextLine));
                data.Document.ClearMarkers(nextLine);
                var loc = data.Caret.Location;
                for (int i = lineEnd + 1; i >= lineStart; i--)
                {
                    DocumentLine cur  = data.Document.GetLine(i);
                    DocumentLine prev = data.Document.GetLine(i - 1);
                    data.Replace(cur.Offset, cur.Length, i != lineStart ? data.Document.GetTextAt(prev.Offset, prev.Length) : text);
                    data.Document.ClearMarkers(data.Document.GetLine(i));
                    foreach (TextLineMarker marker in (i != lineStart ? data.Document.GetMarkers(data.Document.GetLine(i - 1)) : prevLineMarkers))
                    {
                        data.Document.AddMarker(data.Document.GetLine(i), marker);
                    }
                }

                data.Caret.Location = new DocumentLocation(loc.Line + 1, loc.Column);
                if (setSelection)
                {
                    data.SetSelection(anchor.Line + 1, anchor.Column, lead.Line + 1, lead.Column);
                }
            }
        }
        static string StripHeaderAndBlankLines(string text, CodeDomProvider provider)
        {
            Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument();
            doc.Text = text;
            int realStartLine = 0;

            for (int i = 1; i <= doc.LineCount; i++)
            {
                string lineText = doc.GetTextAt(doc.GetLine(i));
                // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags.
                if (lineText.Contains("</autogenerated>") || lineText.Contains("</auto-generated>"))
                {
                    realStartLine = i + 2;
                    break;
                }
            }

            // The Mono provider inserts additional blank lines, so strip them out
            // But blank lines might actually be significant in other languages.
            // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines
            if (provider is Microsoft.CSharp.CSharpCodeProvider)
            {
                bool previousWasBlank = false;
                for (int i = 1; i <= doc.LineCount; i++)
                {
                    Mono.TextEditor.DocumentLine line = doc.GetLine(i);
                    bool isBlank, isBracket;
                    CheckLine(doc, line, out isBlank, out isBracket);
                    if (isBlank && previousWasBlank && line.LengthIncludingDelimiter > 0)
                    {
                        doc.Remove(line.Offset, line.LengthIncludingDelimiter);
                        i--;
                    }
                    previousWasBlank = isBlank || isBracket;
                }
            }

            int offset = doc.GetLine(realStartLine).Offset;

            return(doc.GetTextAt(offset, doc.TextLength - offset));
        }
 static void CheckLine(Mono.TextEditor.TextDocument doc, Mono.TextEditor.DocumentLine line, out bool isBlank, out bool isBracket)
 {
     isBlank   = true;
     isBracket = false;
     for (int i = 0; i < line.LengthIncludingDelimiter; i++)
     {
         char c = doc.GetCharAt(line.Offset + i);
         if (c == '{')
         {
             isBracket = true;
             isBlank   = false;
         }
         else if (!Char.IsWhiteSpace(c))
         {
             isBlank = false;
             if (isBracket)
             {
                 isBracket = false;
                 break;
             }
         }
     }
 }
		public DocumentLineWrapper (Mono.TextEditor.DocumentLine line)
		{
			if (line == null)
				throw new ArgumentNullException ("line");
			this.Line = line;
		}