Adi*_*Adi 6 visual-studio-code vscode-extensions
在为 vscode 创建扩展时,我陷入了选择中,现在问题是当我通过 api 替换某些范围的 textEditor 时,它会替换该范围并选择该范围。对于片段,这是一个好主意,但我的扩展要求不是选择替换文本,我在 api 中搜索但没有找到与删除文本选择相关的任何内容(选择发生在文档为空时)
editor.edit((editBuilder)=>{ //editor is an object of active text editor
editBuilder.replace(textRange,text) // text = 'dummydummydummy'
}) //after this I got the following output
Run Code Online (Sandbox Code Playgroud)
小智 5
editor.edit(builder => {
builder.replace(selection, newStr);
})
// The edit call returns a promise. When that resolves you can set
// the selection otherwise you interfere with the edit itself.
// So use "then" to sure edit call is done;
.then(success => {
console.log("success:", success);
// Change the selection: start and end position of the new
// selection is same, so it is not to select replaced text;
var postion = editor.selection.end;
editor.selection = new vscode.Selection(postion, postion);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2101 次 |
最近记录: |