Completed
Last Updated: 19 Jun 2017 12:14 by ADMIN
ADMIN
Dimitar
Created on: 13 Mar 2017 12:00
Category: Editors
Type: Bug Report
0
FIX. RadTextBoxControl - the performance is slow when using the AppendText method.
The issue exist in the versions after Q1 2017

Workaround:
Class MyTextBox
    Inherits RadTextBoxControl

    Protected Overrides Function CreateTextBoxElement() As RadTextBoxControlElement
        Return New MyTextBoxElement()

    End Function
End Class

Class MyTextBoxElement
    Inherits RadTextBoxControlElement
    Protected Overrides ReadOnly Property ThemeEffectiveType As Type
        Get
            Return GetType(RadTextBoxControlElement)

        End Get
    End Property
    Protected Overrides Function CreateViewElement() As TextBoxViewElement
        Return New MyWrapPanel

    End Function
End Class

Class MyWrapPanel
    Inherits TextBoxViewElement

    Protected Overrides Function InsertTextBlocks(index As Integer, text As String, blockType As Type) As Integer

        If String.IsNullOrEmpty(text) Then
            Return index
        End If

        Dim textBuilder As New StringBuilder()

        For i As Integer = 0 To text.Length - 1
            Dim symbol As Char = text(i)

            If Char.IsWhiteSpace(symbol) OrElse symbol = TextBoxViewElement.TabSymbol OrElse symbol = TextBoxViewElement.LineFeedSymbol OrElse symbol = TextBoxViewElement.CarriageReturnSymbol Then
                If textBuilder.Length > 0 Then
                    Dim textBlock As ITextBlock = Me.CreateBlock(textBuilder.ToString(), blockType)
                    If index >= Me.Children.Count Then
                        Me.Children.Add(TryCast(textBlock, RadElement))
                        index = Me.Children.Count - 1
                        textBlock.Index = index
                    Else
                        textBlock.Index = index
                        Me.Children.Insert(index, TryCast(textBlock, RadElement))
                    End If

                    textBuilder = New StringBuilder()

                    index += 1
                End If

                Dim tabBlock As ITextBlock = Me.CreateBlock(symbol.ToString(), blockType)
                tabBlock.Index = index
                Me.Children.Insert(index, TryCast(tabBlock, RadElement))
                index += 1
                Continue For
            End If

            textBuilder.Append(symbol)
        Next

        If textBuilder.Length > 0 Then
            Dim textBlock As ITextBlock = Me.CreateBlock(textBuilder.ToString(), blockType)
            textBlock.Index = index
            Me.Children.Insert(index, TryCast(textBlock, RadElement))
            index += 1
        End If

        Return index - 1
    End Function
End Class
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
4 comments
ADMIN
Stefan
Posted on: 19 Jun 2017 12:14
Hi David,

the issue is resolved with the R2 2017 release. Please upgrade to it or the latest version in order to take advantage of the fix.
David
Posted on: 29 Mar 2017 20:49
Actually, I take back my comment. It definitely helped, but after a while the text box becomes very slow to update and once again freezes the UI thread of the application while appending text... What gives?
David
Posted on: 29 Mar 2017 20:24
I can confirm it fixed my issue as well. Converted to C#:

public class MyTextBox : RadTextBoxControl
{

	protected override RadTextBoxControlElement CreateTextBoxElement()
	{
		return new MyTextBoxElement();

	}
}

public class MyTextBoxElement : RadTextBoxControlElement
{
	protected override Type ThemeEffectiveType {

		get { return typeof(RadTextBoxControlElement); }
	}
	protected override TextBoxViewElement CreateViewElement()
	{
		return new MyWrapPanel();

	}
}

public class MyWrapPanel : TextBoxViewElement
{

	protected override int InsertTextBlocks(int index, string text, Type blockType)
	{

		if (string.IsNullOrEmpty(text)) {
			return index;
		}

		StringBuilder textBuilder = new StringBuilder();

		for (int i = 0; i <= text.Length - 1; i++) {
			char symbol = text[i];

			if (char.IsWhiteSpace(symbol) || symbol == TextBoxViewElement.TabSymbol || symbol == TextBoxViewElement.LineFeedSymbol || symbol == TextBoxViewElement.CarriageReturnSymbol) {
				if (textBuilder.Length > 0) {
					ITextBlock textBlock = this.CreateBlock(textBuilder.ToString(), blockType);
					if (index >= this.Children.Count) {
						this.Children.Add(textBlock as RadElement);
						index = this.Children.Count - 1;
						textBlock.Index = index;
					} else {
						textBlock.Index = index;
						this.Children.Insert(index, textBlock as RadElement);
					}

					textBuilder = new StringBuilder();

					index += 1;
				}

				ITextBlock tabBlock = this.CreateBlock(symbol.ToString(), blockType);
				tabBlock.Index = index;
				this.Children.Insert(index, tabBlock as RadElement);
				index += 1;
				continue;
			}

			textBuilder.Append(symbol);
		}

		if (textBuilder.Length > 0) {
			ITextBlock textBlock = this.CreateBlock(textBuilder.ToString(), blockType);
			textBlock.Index = index;
			this.Children.Insert(index, textBlock as RadElement);
			index += 1;
		}

		return index - 1;
	}
}
David
Posted on: 29 Mar 2017 20:01
Going to try this out, it literally freezes my whole application right now once even a modest amount of text gets appended.