Using a text area gadget to create a simple editor

BlitzMax Forums/MaxGUI Module/Using a text area gadget to create a simple editor

TomToad(Posted 2010) [#1]
I am trying to create a simple code editor using a text area gadget. I don't need many features, but two I would like to have are syntax highlighting and auto indenting.

For syntax highlighting, I figured I could just get the current line being edited and parse it, then format the line according to the code there.

But I'm having problems with the auto indenting. I figured I could just detect when the enter key is pressed and check the previous line for tab characters, then insert that many into the current line. Unfortunately, it seems the text area gadget won't pass EVENT_KEYDOWN or EVENT_KEYUP events.

Any ideas how I can accomplish this? I tried looking at the MaxIDE code, but I am clueless how things are set up there.


BLaBZ(Posted 2010) [#2]
I believe you need to SetGadgetFilter


TomToad(Posted 2010) [#3]
Thanks BLaBZ, that seems to do what I want.

Another question, after inserting the tabs, the cursor remains at the spot before the tabs. How can I move the cursor so it is after the tabs? I cant see any SetAreaTextCursor command.


TomToad(Posted 2010) [#4]
Seems that making a simple editor is not so simple after all. Here is what I have so far. Only the keyword "print" is highlighted at the moment, but it works.
Unfortunately, I cannot get auto-indenting to work. I tried using TextAreaText() to get the text, insert the tabs, then using SetTextAreaText() to write the text back. The tabs were inserted, but the cursor was not updated, and it messed up the formatting.
I then tried EmitEvent() to emit a fake keypress, but it seems to not work either.
Anyone have any idea how I can insert tabs before the cursor or fake the keypresses, and not mess up the formatting?

current code:



Dabhand(Posted 2010) [#5]
http://www.blitzmonkeys.com/index.php?topic=4.0

May help!

Dabz