Hi

I'm developing a (very) simple editor (more like a proof of concept thing - but anywho..)

I just finished the plugin framework and stated to create a "snippet" plugin for the editor, when i ran in to some trouble.
I'll just briefly explain what I'm aiming for with the plugin:
The user types in a word (the snippet trigger) and presses tab, and a bunch of common code pops into the editor. (just like the snippets in VS).
Ex:
The user types "for" and presses tab and the following code appears in the editor:
"for(int i = 0; i < length; i++){}"

So far so good, I've managed to implement that, but I'd like the snippets to have "input fields": If the user presses tab a second time the cursor is moved to the first "i" and the user is able to change all the "i" at once (again just like in VS).

When fiddling around with this i was storing the position where the snippet was inserted into the text, and the positions of the interactive places in the snippet. But this includes a lot of searching trough the text and adding and subtracting and is very error prone. And the positions of the fields must be updated when ever the user types in a field that is before another field. So this quickly became complicated and rather clumsy.

So back in the editor (I'd like it to expose an interface for these kinds of plugins) I tried to figure out a way to do this more elegant. I though storing the text in a data structure outside the textbox and maybe adding HTML/XML tags to the words in the text, and thereby making it easier to find individual words. But this would mean that I would have to traverse the data structure and extract the actual text or use some kind of a renderer instead of a textbox, and that seems a bit overkill.

So my question is this. Is there some kind of standard way of storing the text in an editor (a part from a string in mem.), and adding some data to the text, or parts of the text. I would think that the same kind of problem would arise when I'm to make a syntax highlighter plugin later.

Thanks!