我正在使用 VSCode API 构建扩展,但我没有找到介绍如何获取用户突出显示的文本的文档,如下所示:
有一个类似的问题regarding the word the cursor is currently on ,但我想抓取整个突出显示的文本。
最佳答案
该解决方案是 Mark's answer here. 的修改版本
const editor = vscode.window.activeTextEditor;
const selection = editor.selection;
if (selection && !selection.isEmpty) {
const selectionRange = new vscode.Range(selection.start.line, selection.start.character, selection.end.line, selection.end.character);
const highlighted = editor.document.getText(selectionRange);
}
关于visual-studio-code - 如何从 VSCode 扩展 API 获取突出显示的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73043106/