Search code examples
keywordace-editor

How to find out the keyword in ace-editor


For ace-editor, I want to select one line and find out all the keywords within the line and output into the console. Which APIs from ace-editor that I can use for this purpose, and how to achieve the goal. Thanks.


Solution

  • you can use session.getTokens method like so

    var row = editor.selection.getCursor().row
    editor.session.getTokens(row).filter(function(t) {
        return t.type == "keyword"
    })