Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get token string for ace editor

I just looked at the kitchen sink demo and see that there is an option "Show token info" that shows up what type of text the mouse is over (variable, function etc.)

I want to create something similar that can get the current token string of the word at the current cursor position. Does anyone knows how to do that ?

Thanks!

like image 586
amitdar Avatar asked Dec 05 '12 14:12

amitdar


1 Answers

In this way:

editor.on('mousemove', function(e) {
    var position = e.getCursorPosition();
    var token = editor.session.getTokenAt(position.row, position.column);

});

It will return an Object:

token = {
  type: "paren.rparen",
  value: "}",
  index: 0,
  start: 0
} 
like image 126
koMah Avatar answered Sep 21 '22 09:09

koMah