Hightlight a textarea?

BlitzMax Forums/MaxGUI Module/Hightlight a textarea?

Sanctus(Posted 2008) [#1]
How can I do that?
I tryed to write some code that looks like this
Local txt:String = TextAreaText(ScriptEditTA)
					txt = txt.ToLower()
					For Local i:Int = 0 To KeyWords.Length - 1
						Local lp:Int = -1
						Local KW:String = KeyWords[i].ToLower()
						lp = txt.Find(KW, lp + 1)
						While(lp >= 0)
							Local l:Int = Len(KW)
							SetTextAreaText(ScriptEditTA, KeyWords[i], lp, l)
							FormatTextAreaText(ScriptEditTA, 0, 0, 255, TEXTFORMAT_BOLD, lp, l)
							lp = txt.Find(KW, lp + 1)
						Wend
					Next

but if I write something it colors all the words after that keywords.


klepto2(Posted 2008) [#2]
AS far as I remember you have to reset the Format after you have formatted a piece of the text.
eg: FormatTextAreaText(scriptEditTA,0,0,0,0,lp+1,1)

Also just 3 things I have noticed:
I don't know how much keywords you have, but it may be faster to switch to TMaps instead of using arrays. The main advantage is you are able to add the heyword and maybe a keyword type which stores color,format and other things. So you can have different keywordstyles easily.
The other thing, you should get rid of the While loop. Try something like FormatTextAreaText(...,...,...,...,...,lp,KeyWords[i].length)
Also try to avoid to update the whole text at once. Use the hooks and after an inital load, you should only update on a perline basis.

I have some highlighter code flying around here, if you're interrested I can upload it.


SebHoll(Posted 2008) [#3]
Try using SetGadgetTextColor() before parsing and highlighting using FormatTextAreaText to set the base colour of the text.


Dabhand(Posted 2008) [#4]
Here you go:-



It formats the text when it encounters html tags, so load a short html page and you'll see it formats the lot, as well as when your typing! :)

Dabz


slenkar(Posted 2009) [#5]
thanks dabz much appreciated