/// <summary> /// Appends the <paramref name="text"/> to the <see cref="TextBox"/> at the end. /// </summary> /// <param name="text">The text to append.</param> public void Append(StyledText text) { if (text.Text.Length == 0) { return; } if (!IsMultiLine) { _lines.LastLine.Append(text.ToSingleline()); } else { var textLines = StyledText.ToMultiline(text); _lines.LastLine.Append(textLines[0]); for (var i = 1; i < textLines.Count; i++) { var newLine = new TextBoxLine(_lines); _lines.Insert(_lines.Count, newLine); newLine.Append(textLines[i]); } TruncateIfNeeded(); } _numCharsToDraw.Invalidate(); _hasTextChanged = true; }
/// <summary> /// Appends styled text to the line but does NOT invoke the NotifyTextAdded method. This way, multiple /// appends can be made, and NotifyTextAdded is only called once. /// </summary> /// <param name="text">The text to append.</param> void InternalAppend(StyledText text) { if (text == null || text.Text.Length == 0) { return; } // Since this class is a single line, remove any line breaks text = text.ToSingleline(" "); if (text.Text.Length == 0) { return; } // Check if we can combine with the current last StyledText var last = LastStyledText; if (last != null && last.HasSameStyle(text)) { // Append to the existing StyledText _texts[_texts.Count - 1] = last + text.Text; _lineText += text.Text; } else { // Add the new StyledText _texts.Add(text); _lineText += text.Text; } EnsureCacheMatchesActualText(); }
/// <summary> /// Appends the <paramref name="text"/> to the <see cref="TextBox"/> at the end. /// </summary> /// <param name="text">The text to append.</param> public void Append(StyledText text) { if (text.Text.Length == 0) return; if (!IsMultiLine) _lines.LastLine.Append(text.ToSingleline()); else { var textLines = StyledText.ToMultiline(text); _lines.LastLine.Append(textLines[0]); for (var i = 1; i < textLines.Count; i++) { var newLine = new TextBoxLine(_lines); _lines.Insert(_lines.Count, newLine); newLine.Append(textLines[i]); } TruncateIfNeeded(); } _numCharsToDraw.Invalidate(); _hasTextChanged = true; }
public void ToSingleLineWithReplacementTest() { var a = new StyledText("abc\rdefg\r\nhij\r\nklm\nn"); Assert.AreEqual("abcXdefgXhijXklmXn", a.ToSingleline("X").Text); }
public void ToSingleLineTest() { var a = new StyledText("abc\rdefg\r\nhij\r\nklm\nn"); Assert.AreEqual("abcdefghijklmn", a.ToSingleline().Text); }
/// <summary> /// Appends styled text to the line but does NOT invoke the NotifyTextAdded method. This way, multiple /// appends can be made, and NotifyTextAdded is only called once. /// </summary> /// <param name="text">The text to append.</param> void InternalAppend(StyledText text) { if (text == null || text.Text.Length == 0) return; // Since this class is a single line, remove any line breaks text = text.ToSingleline(" "); if (text.Text.Length == 0) return; // Check if we can combine with the current last StyledText var last = LastStyledText; if (last != null && last.HasSameStyle(text)) { // Append to the existing StyledText _texts[_texts.Count - 1] = last + text.Text; _lineText += text.Text; } else { // Add the new StyledText _texts.Add(text); _lineText += text.Text; } EnsureCacheMatchesActualText(); }