Skip to main content
July 5, 2010
Answered

Spark TextArea, setFormatOfRange performance issue

  • July 5, 2010
  • 1 reply
  • 991 views

Hi, dear

I am building the syntax highlight editor by using spark.components.textarea

my app invokes setFormatOfRange to put colour on syntax. but I find this API is very very slow.

I need wait more than 10s before the UI response me


And if I comment the setFormatOfRange, it runs smoothly without delay

Seems the TLF is very slow at this point, isn't it?

Must I change back to use mx.controls.TextArea?  is that faster?

thank you

This topic has been closed for replies.
Correct answer

Richard's solution is the fastest solution you can get to format a great number of words in a TextArea. Unfortunately, this solution might not be suitable in some cases. Let's say you listen for TextOperationEvent.CHANGE on a TextArea to get text changes and based on them to highlight some words (similar to a code editor). If you apply format using interactionManager, you will get another TextOperationEvent.CHANGE and that may lead to an infinite loop.

What I did was to find out how setFormatOfRange works and mimic the code inside that method, using the ApplyFormatOperation and CompositeOperation. Of course, usually you won't have to deal with such operations because that's the purpose of EditManager, but sometimes you just need a quick and working solution.

You could check this post for more details on how to use operations to format text inside a RichEditableText.

1 reply

Adobe Employee
July 7, 2010

Issue is that RichEditableText.setFormatOfRange updates the display on every call.  What you want to do is directly access the TextFlow (its a property of RichEditableText), make all of your format changes and then update the display using TLF APIs.

Something like this

var textFlow:TextFlow = ret.textFlow

textFlow.interactionManager.beginCompositeOperation

textFlow.interactionManager.applyLeafFormat  (as many times as necessary)

textFlow.interactionManager.endCompoisteOperation

The composite operation calls let you do multiple updates without updating the display.  There may be some additional things needed to make sure the textFlow has an interactionManager.

RIchard

Correct answer
August 27, 2010

Richard's solution is the fastest solution you can get to format a great number of words in a TextArea. Unfortunately, this solution might not be suitable in some cases. Let's say you listen for TextOperationEvent.CHANGE on a TextArea to get text changes and based on them to highlight some words (similar to a code editor). If you apply format using interactionManager, you will get another TextOperationEvent.CHANGE and that may lead to an infinite loop.

What I did was to find out how setFormatOfRange works and mimic the code inside that method, using the ApplyFormatOperation and CompositeOperation. Of course, usually you won't have to deal with such operations because that's the purpose of EditManager, but sometimes you just need a quick and working solution.

You could check this post for more details on how to use operations to format text inside a RichEditableText.