Hightlight a textarea?
BlitzMax Forums/MaxGUI Module/Hightlight a textarea?
| ||
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. |
| ||
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. |
| ||
Try using SetGadgetTextColor() before parsing and highlighting using FormatTextAreaText to set the base colour of the text. |
| ||
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 |
| ||
thanks dabz much appreciated |