How can I traverse through tokens

So what I’m trying to do is basically travesing through tokens, I asked it in stackoverfow already:

I know codemirror doesn’t designed for this but maybe there’s a way to do it…

I don’t know much about codemirror internals so if you could give me a hint about the logic that would really help.

So I think it’s about the position of tokens and moving between them. If I could seek for src token and some string after that and get it’s position somehow I can use it to set a selection and use replaceSelection method to do the replacement…

Thanks in advance.

You can either use the runmode addon, or call getLineTokens for each line.

Needed to get the line tokens from the start of the line to the cursor’s current position.

var cursor = cm.getDoc().getCursor();
var lineTokens = cm.getLineTokens(cursor.line).filter(t => t.start <;

Figured I’d share this snippet since I imagine that’s the most frequent type of traversal through tokens.
I’m really enjoying this application. Thank you for your work on it.