Reading TextArea.StyledText.StyleRunCount causes entire TextArea to refresh under Win32

Reading TextArea.StyledText.StyleRunCount causes entire TextArea to refresh under Win32

Type in the TextArea.

dim u as integer = me.StyledText.StyleRunCount()

This seems to trigger the entire text area to flash and refresh line by line.

Tested on Windows 10.10 (64 bit)

Bug is present in Xojo 2014R2.1 as well as the latest 2015 R3 beta.


More info - this is a very strange issue.

If you run the app in Remote Debug on Windows 10 (64 bit) then the behavior is very noticeable : each time .StyleRunCount() is called the entire TextArea refreshes multiple times - possibly one refresh for each line - you can actually see the TextArea’s scollbar run from top to bottom, and when it finishes the TextArea scroll position has changed.

If you run the compiled app the behavior is different: you don’t see the massive screen refresh, but there is a pause, and the scroll position is altered.

Note: calling StyledText.RTFData() appears to trigger the same behavior. I wonder if StyledText.RTFData() uses StyleRunCount() internally, or perhaps vice-versa?

Either way, however, this bug is a bad one as it makes using StyledText in a Win32 app completely unusable.

Bump - am I the only one having this trouble? As far as I can tell, this makes using StyledText and RTFData nearly impossible in a Win32 app under Windows 10. What are you all doing?

I’ve tried a workaround using MBS plugins function TextArea.WinRTFDataMBS : this works to avoid the flashing, and the RTF data (though not identical) looks close enough to what Xojo gives.

However, trying to use TextArea.StyledText.RTFDataMBS does not work: the TextArea still shows horrible updating / flashing behavior. (Not sure if this is MBS fault of perhaps just the call to TextArea.StyledText() is the problem).

I think I can refactor my code a bit to avoid using StyledText in most cases, instead using MBS’s TextArea.WinRTFDataMBS function.

Is this a Win10 thing only? I can’t see this in Win7, but I am not sure if I am doing what you are doing.

I thought about copying the styled content to a “shadow” TextArea off screen and count runs there, but It seems the simple fact to retrieve StyledText.RTFData creates the issue. It is possible MBS does not do that, but I did not test.

The workaround would seem to be to count StyleRuns at the text load, then keep an array containing each styleRun. Whenever the user changes font, color, textsize, you can check against the array if the style already exist, and if needed, add one to your collection. That won’t flicker.

The only time when counting styleruns would seem again necessary is in case of text deletion, or if the user pastes a block of text.

I am curious, though, as why you need to know the number of styleRuns in keydown. Would it not be possible to get that value less often ?

Are you testing the sample project I uploaded?

I actually don’t want that information, what I really want is the RTF data; I was attempting to use StyleRunCount() in a routine which calculated the RTF data for me (which avoids all the other RTFData bugs in Xojo). The “cure” is no better than the disease, in this case.

It would be nice to have the RTFData in real time on a per-keypress basis, but it’s probably not necessary: I could just check it when the TextArea loses focus instead.

I see it now yes. Even using the StyledText class and not “manipulating” the StyledText directly on the TextArea seems to do it.