Advice for particular kind of flicker

Here is the setup: I have a TextArea that I am coloring as the user types. In the background, with every TextChange, the colors are all cleared, then the new colors applied character by character. In order to speed this up, I preserve the properties of the TextArea (SelStart, etc.), then make it invisible. When I’m done, I restore the properties and make it visible again. Functionally, this works perfectly. Visually, it causes a terrible flicker if the user types quickly.

If I don’t make the TextArea invisible, the user sees a scrolling effect that is even worse, so that doesn’t seem to be an option. I tried FreezeUpdate from the Windows Functionality Suite, but that makes the whole field go away unless I force a Window.Refresh, and that makes the whole window flicker.

Advice?

(If anyone wants to see the effect, it’s RegExRX 1.8b36 here. You can compare it to the Mac version which actually does more behind the scenes, but is smooth as silk. Download the Samples under the Help menu, then look at the Validate Email Address (Complex) file for a real stress test.)

why not use TWO textareas? one off screen where you do all the coloring and then transfer that to the visible one…

And do you need to redo the WHOLE thing? You might want to look at FTC or Alex Restrepos Edit control… both do syntax highlighting.
I use the code for ALex alot, and it works very well until lyou get into a few megabyte of text…

Yes, I have to do the whole thing because the color of the syntax is dependent on what came before. For example, if you have a “?”, that would be one color unless there is a paren right before it. Then it takes on the color of the paren, but the color of the paren is dependent on the level of its nesting. Of course, it might not be a real paren at all if it’s between square brackets, and wait, what if it’s after a “\Q”, which means “literal”? And if there is a “” thrown somewhere into the mix, well, that’s something else altogether.

But the colorization takes milliseconds at worst, so that’s not really the big issue. (About 40-90 ms in Cocoa, if I use the declares for BeginEditing/EndEditing. That’s down from over a second without those.) (This is testing with a 6 k pattern, which is definitely not the norm.)

Colorizing in an off-screen TextArea is something I hadn’t considered. Can I just assign the StyledText from it to the visible one? I’ll have to try that in the morning. My fear is that, once I do that, it will do the scrolling thing that leaving the field visible in the first place did. I’ll find out.

Thanks for the suggestion.

SUB clone_StyledText(master as StyledText, byref Clone as styledText)
  Dim i As Integer
  Dim sr As StyleRun
  For i=0 To master.StyleRunCount-1
    sr=New StyleRun
    sr.Bold=master.StyleRun(i).Bold
    sr.Font=master.StyleRun(i).Font
    sr.Italic=master.StyleRun(i).Italic
    sr.Size=master.StyleRun(i).size
    sr.text=master.StyleRun(i).text
    sr.TextColor=master.StyleRun(i).TextColor
    sr.Underline=master.stylerun(i).Underline
    clone.InsertStyleRun sr,i
  Next i
END SUB

Here is what I used in one of my apps.

And this is on Windows? And there is no flicker?

Even though you do have to process the entire string to get the colors right, I really doubt that you’re changing all the colors every time. You might be able to get away with only changing the ones that are different. That would allow you to do it in place via the SelXXX properties with little to no flicker.

I’m not changing all the colors, but almost every character will have some color applied, and there used to be problem of styles “stacking up” if I didn’t clear them first, resulting in a leak.

Just to give an idea of what a pattern might look like.

This is from the Mac version, and the top field is the one that is troubling me in Windows. I could type two or three letters into an empty Search field on the Windows version and get the flicker if I do it fast enough. Do you think using the Sel… properties will make a difference, and would be fast enough? I ask because, unless I set Visible to false first, the colorization is s-l-o-w.

Is it the top field that is flickering? Or when you color the source text?

Technically both, but it’s much more noticeable in the top field (Search Pattern) because it’s colorizing as the user types. And, as mentioned, I set Visible to false, apply the colors, and set it back to true for speed. It’s at that moment that it flickers, I think.

Ok, but as you’re typing, are you really changing the color on all the characters? Or just a few? If just a few, Selxxx should do the trick.

Technically, I guess I only need to update the colors on whatever has changed, and everything after it. But I need to “read” the pattern from the beginning to know which colors to use. I also need a good way to see where the difference point is from the old string. I guess I could compare bytes in MemoryBlocks for that.

I will try to use the Sel… methods tomorrow as a test and report back.