[英]In VSCode, how to add a new selection to the document via the API?
嘗試編寫我的第一個 VSCode 擴展時,我遇到了一個簡單的問題。 我通過類似的方式建立了一個新的選擇
var new_sel = new Selection(start, end);
其中start
和end
是vscode.Position
對象。 現在我想將它作為一個選擇添加到我的文檔中,但我很迷茫。 我在vscode.commands.registerTextEditorCommand
命令中,所以我可以訪問TextEditor
和TextEditorEdit
對象及其所有字段,但我在 API 中看不到任何關於從文檔中添加/減去選擇的內容。
如何添加選擇,以便它反映在TextEditor.selections
中? (我試圖簡單地將它推送到那個數組,但我在控制台中收到“調試器附加”錯誤。)
TextEditor.selections
可以簡單地被覆蓋。
但是請注意,嘗試pop
或push
送到TextEditor.selections
對我不起作用。
這是訣竅:
let mySelections: vscode.Selection[] = [];
let line1 = 12, char1 = 5, line2 = 20, char2 = 3; //Just some examples.
let line3 = 29, char3 = 3, line4 = 26, char4 = 7; //Just some examples.
mySelections.push(line1, char1, line2, char2);
mySelections.push(line3, char3, line4, char4);
vscode.window.activeTextEditor.selections = mySelections;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.