Ejemplo n.º 1
0
        public virtual void IndentLine(ITextEditor editor, IDocumentLine line)
        {
            IDocument document   = editor.Document;
            int       lineNumber = line.LineNumber;

            if (lineNumber > 1)
            {
                IDocumentLine previousLine = document.GetLine(lineNumber - 1);
                string        indentation  = DocumentUtilitites.GetWhitespaceAfter(document, previousLine.Offset);
                // copy indentation to line
                string newIndentation = DocumentUtilitites.GetWhitespaceAfter(document, line.Offset);
                document.Replace(line.Offset, newIndentation.Length, indentation);
            }
        }
Ejemplo n.º 2
0
        public ReadOnlyDocument(ITextBuffer textBuffer)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException("textBuffer");
            }
            // ensure that underlying buffer is immutable
            this.textBuffer = textBuffer.CreateSnapshot();
            List <int> lines = new List <int>();

            lines.Add(0);
            int    offset = 0;
            string newlineType;
            var    textSource = DocumentUtilitites.GetTextSource(this.textBuffer);

            while ((offset = ICSharpCode.AvalonEdit.Document.TextUtilities.FindNextNewLine(textSource, offset, out newlineType)) >= 0)
            {
                offset += newlineType.Length;
                lines.Add(offset);
            }
            this.lines = lines.ToArray();
        }