Exemplo n.º 1
0
        /// <summary>
        /// Create <see cref="NewFolding"/>s for the specified document.
        /// </summary>
        public IEnumerable <NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
        {
            firstErrorOffset = 0;
            if (document.TextLength < 1)
            {
                return(Enumerable.Empty <NewFolding>());
            }

            try
            {
                if (document.IndexOf('<', 0, document.TextLength) < 0)
                {
                    return(Enumerable.Empty <NewFolding>());
                }
                var reader = new XmlTextReader(document.CreateReader())
                {
                    XmlResolver = null // don't resolve DTDs
                };
                return(CreateNewFoldings(document, reader, out firstErrorOffset));
            }
            catch (XmlException)
            {
                return(Enumerable.Empty <NewFolding>());
            }
        }
Exemplo n.º 2
0
        public async Task Multiple_matches_are_found()
        {
            var searched = "Lorem";

            var text =
                @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Etiam egestas leo urna, vel mollis urna sollicitudin non. 
Nam in orci ante. Praesent dapibus id purus sit amet molestie.
Maecenas erat ex, tempus vitae consectetur et, ullamcorper eget nibh. Nulla facilisi. 
Phasellus nec bibendum lorem. ALoremliquam ac est vitae neque placerat sollicitudin vitae nec odio. 
Aliquam cursus arcu quis magna feugiat, eget consectetur lorem accumsan.
Nam nibh est, aliquam eget ante ac, lacinia sceleLoremrisque eros. Phasellus commodo massa lacus. 
Ut aliquet fermentum tortor at egestas. Aliquam erat leo, auctor ut luctus sed,
aliquam id ligula. Cras eleifend sapien et tellus maximus, in fermentum leo
consectetur.Sed volutpat augue porttitor odLoremio dictum, et semper nisi tempor.
Quisque at aliquam turpis. Duis molestie lacus vitae eros tempor vehicula. ";

            var offsets = new List <int>()
            {
                0, 302, 496, 748
            };
            var offsetsResult = new List <int>()
            {
            };
            var          document = new TextDocument(text);
            var          token    = new CancellationToken();
            Action <int> onFound  = (int offset) => offsetsResult.Add(offset);
            var          sut      = new SearchJob(document.CreateReader(), searched, onFound);

            await sut.RunAsync(token);

            CollectionAssert.AreEquivalent(offsets, offsetsResult);
        }
 /// <summary>
 /// Create <see cref="T:ICSharpCode.AvalonEdit.Folding.NewFolding" />s for the specified document.
 /// </summary>
 public IEnumerable <NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
 {
     try {
         return(CreateNewFoldings(document, new YamlReader(document.CreateReader()), out firstErrorOffset));
     }
     catch (XmlException ex) {
         firstErrorOffset = 0;
         return(Enumerable.Empty <NewFolding>());
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create <see cref="NewFolding"/>s for the specified document.
 /// </summary>
 public IEnumerable <NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
 {
     try {
         XmlTextReader reader = new XmlTextReader(document.CreateReader());
         reader.XmlResolver = null;                 // don't resolve DTDs
         return(CreateNewFoldings(document, reader, out firstErrorOffset));
     } catch (XmlException) {
         firstErrorOffset = 0;
         return(Enumerable.Empty <NewFolding>());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the plain content of a <see cref="TextDocument" />.
        /// </summary>
        /// <param name="doc">The text document.</param>
        /// <returns>
        /// The content of <paramref name="doc" /> or <see langword="null" />
        /// if <paramref name="doc" /> is also a <see langword="null" /> reference.
        /// </returns>
        public static string ToString(TextDocument doc)
        {
            if (doc == null)
            {
                return(null);
            }

            using (var reader = doc.CreateReader())
            {
                return(reader.ReadToEnd());
            }
        }
Exemplo n.º 6
0
        public async Task Text_is_not_found_if_no_match_found(string text, string searched)
        {
            var          offsets  = new List <int>();
            var          document = new TextDocument(text);
            var          token    = new CancellationToken();
            Action <int> onFound  = (int offset) => offsets.Add(offset);
            var          sut      = new SearchJob(document.CreateReader(), searched, onFound);

            await sut.RunAsync(token);

            Assert.AreEqual(0, offsets.Count);
        }
Exemplo n.º 7
0
        public void IndentLine(TextDocument document, DocumentLine line, bool TakeCaret)
        {
            if (line.PreviousLine == null)
            {
                return;
            }

            if (!DSettings.Instance.EnableSmartIndentation)
            {
                var prevIndent = ReadRawLineIndentation(document.GetText(line));

                RawlyIndentLine(prevIndent, document, line);

                return;
            }

            var tr    = document.CreateReader();
            var block = CalculateIndentation(tr, line.LineNumber);

            tr.Close();

            RawlyIndentLine(block != null ? block.GetLineIndentation(line.LineNumber) : 0, document, line);
        }
 TextReader MonoDevelop.Core.Text.ITextSource.CreateReader()
 {
     return(document.CreateReader());
 }