获取ace编辑器的令牌字符串

ami*_*dar 11 token ace-editor

我只是看了厨房水槽演示,看到有一个选项"显示令牌信息",显示鼠标所在的文本类型(变量,功能等)

我想创建类似的东西,可以获取当前光标位置的单词的当前标记字符串.有谁知道怎么做?

谢谢!

小智 14

通过这种方式:

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

});
Run Code Online (Sandbox Code Playgroud)

它将返回一个Object:

token = {
  type: "paren.rparen",
  value: "}",
  index: 0,
  start: 0
} 
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,正是我需要的!看起来好像检索位置的函数已经改变了:`e.getCursorPosition()`. (2认同)
  • 请注意,**鼠标**位置与**光标**位置不同.你应该使用`editor.onCursorChange`而不是`mousemove`事件.(除非你想检测鼠标指针所在的那个标记,在这种情况下我很难过!) (2认同)