[英]How to get highlighted text from VSCode Extension API
您可以使用activeTextEditor
API 調用來使用活動文本編輯器,然后使用selections
字段來獲取您的選擇范圍。 您的代碼將如下所示:
let editor = vscode.window.activeTextEditor
let selections = editor.selections
VSCode API 文檔: https ://code.visualstudio.com/api/references/vscode-api#TextEditor
解決方案是Mark's answer here 的修改版本。
const editor = vscode.window.activeTextEditor;
const selection = editor.selection;
if (selection && !selection.isEmpty) {
const firstSelectedCharacter = selection.start.character;
const selectionRange = new vscode.Range(selection.start.line, firstSelectedCharacter, selection.end.line, selection.end.character);
const highlighted = editor.document.getText(selectionRange);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.