在为 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
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 position = editor.selection.end;
editor.selection = new vscode.Selection(position, position);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)