Search code examples
ace-editor

Get next token type in Ace Editor


With the session you are able to get a token using:

token = session.getTokenAt(row, column);
token.type; // text.xml

Is there a way to get the next token type?

token = session.getTokenAt(row, column);
token.type; // text.xml
token = session.getNextToken(token);
token.type; // meta.tag.punctuation.end-tag-open.xml

I have a value that has a data URI string and I would like to skip to the next token.

Example XML:

<data>
    abcdef...
    abcdef...
    ...5000 more rows...
</data>

Example XML attribute:

<data src="abcdef...5000 characters..." />

Solution

  • use token iterator

    var TokenIterator = require("ace/token_iterator").TokenIterator;
    var stream = new TokenIterator(session, row, column);
    next = stream.stepForward()
    

    https://github.com/ajaxorg/ace/blob/v1.2.8/lib/ace/mode/folding/latex.js#L87