Ren*_*oth 3 visual-studio-code vscode-extensions
我不是在谈论当前的选择,它可以通过vscode.window.activeTextEditor.selection
.
当光标位于标识符、变量名称等内时,它会突出显示,如下图所示:
这个高亮对象叫什么?我如何访问它?
搜索从“突出显示”到“标识符”以及其他任何内容,答案更加明显。TextDocument
有一个getWordRangeAtPosition
方法,它接受一个位置并返回单词的范围。
const editor = vscode.window.activeTextEditor;
let cursorPosition = editor.selection.start;
let wordRange = editor.document.getWordRangeAtPosition(cursorPosition);
let highlight = editor.document.getText(wordRange);
// highlight will now contain the currently highlighted word
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1635 次 |
最近记录: |