Exemple #1
0
        /// <summary>
        /// Sets the total line length and checks the delimiter.
        /// This method can cause line to be deleted when it contains a single '\n' character
        /// and the previous line ends with '\r'.
        /// </summary>
        /// <returns>Usually returns <paramref name="line"/>, but if line was deleted due to
        /// the "\r\n" merge, returns the previous line.</returns>
        DocumentLine SetLineLength(DocumentLine line, int newTotalLength)
        {
//			changedLines.Add(line);
//			deletedOrChangedLines.Add(line);
            int delta = newTotalLength - line.TotalLength;

            if (delta != 0)
            {
                foreach (ILineTracker lt in lineTrackers)
                {
                    lt.SetLineLength(line, newTotalLength);
                }
                line.TotalLength = newTotalLength;
                DocumentLineTree.UpdateAfterChildrenChange(line);
            }
            // determine new DelimiterLength
            if (newTotalLength == 0)
            {
                line.DelimiterLength = 0;
            }
            else
            {
                int  lineOffset = line.Offset;
                char lastChar   = textBuffer.GetCharAt(lineOffset + newTotalLength - 1);
                if (lastChar == '\r')
                {
                    line.DelimiterLength = 1;
                }
                else if (lastChar == '\n')
                {
                    if (newTotalLength >= 2 && textBuffer.GetCharAt(lineOffset + newTotalLength - 2) == '\r')
                    {
                        line.DelimiterLength = 2;
                    }
                    else if (newTotalLength == 1 && lineOffset > 0 && textBuffer.GetCharAt(lineOffset - 1) == '\r')
                    {
                        // we need to join this line with the previous line
                        DocumentLine previousLine = line.PreviousLine;
                        RemoveLine(line);
                        return(SetLineLength(previousLine, previousLine.TotalLength + 1));
                    }
                    else
                    {
                        line.DelimiterLength = 1;
                    }
                }
                else
                {
                    line.DelimiterLength = 0;
                }
            }
            return(line);
        }
Exemple #2
0
 public char GetCharAt(int offset)
 {
     VerifyAccess();
     if (offset < 0 || offset >= textBuffer.Length)
     {
         throw new ArgumentOutOfRangeException("offset", offset, "0 <= offset < " + textBuffer.Length.ToString());
     }
     return(textBuffer.GetCharAt(offset));
 }