AvalonStudio.TextEditor.Document.LineManager.SetLineLength C# (CSharp) Method

SetLineLength() private method

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'.
private SetLineLength ( DocumentLine line, int newTotalLength ) : DocumentLine
line DocumentLine
newTotalLength int
return DocumentLine
		private DocumentLine SetLineLength(DocumentLine line, int newTotalLength)
		{
			//			changedLines.Add(line);
			//			deletedOrChangedLines.Add(line);
			var delta = newTotalLength - line.TotalLength;
			if (delta != 0)
			{
				foreach (var lt in lineTrackers)
					lt.SetLineLength(line, newTotalLength);
				line.TotalLength = newTotalLength;
				DocumentLineTree.UpdateAfterChildrenChange(line);
			}
			// determine new DelimiterLength
			if (newTotalLength == 0)
			{
				line.DelimiterLength = 0;
			}
			else
			{
				var lineOffset = line.Offset;
				var lastChar = document.GetCharAt(lineOffset + newTotalLength - 1);
				if (lastChar == '\r')
				{
					line.DelimiterLength = 1;
				}
				else if (lastChar == '\n')
				{
					if (newTotalLength >= 2 && document.GetCharAt(lineOffset + newTotalLength - 2) == '\r')
					{
						line.DelimiterLength = 2;
					}
					else if (newTotalLength == 1 && lineOffset > 0 && document.GetCharAt(lineOffset - 1) == '\r')
					{
						// we need to join this line with the previous line
						var previousLine = line.PreviousLine;
						RemoveLine(line);
						return SetLineLength(previousLine, previousLine.TotalLength + 1);
					}
					else
					{
						line.DelimiterLength = 1;
					}
				}
				else
				{
					line.DelimiterLength = 0;
				}
			}
			return line;
		}