I have some performance problems with large amounts of spans in an EditText
. Actually I'm syntaxhighligthing big source code. To highlight I set the spans with different color and different position. Assume we have the following:
public static void main(String[] args)
My code will output the following tokens (these are just numbers for the example, they could be wrong):
("Keyword", 0, 5) -> public
("Keyword", 7, 12) -> static
("Keyword", 14, 17) -> void
("Type", 24, 29) -> String
and then I set the spans:
for(Lexer.Token t: tokens) {
text.setSpan(new ForegroundColorSpan(colorizer.getColor(t)), t.start, t.end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
Now, assume that I add the char a
at the beginning:
a public static void main(String[] args)
What happens is that all the spans need to be recalculated by adding 2. The problem is that if I have a huge file and so lots of spans, the calculation is slow.
My Idea was to apply the syntaxhighlight only to the visible part of the code, but it's a bit messy to do and I'm searching for a better and easier solution. Has someone a good solution for that?
Thank you in advance