开发 vscode 扩展时,多光标编辑不工作

70 阅读1分钟

// 获取当前编辑器中的多个光标位置
const selections = editor.selections
let count = selections.length
selections.forEach(selection => {
    // 在光标位置插入连续数字        
    void editor.edit(editBuilder => {
        editBuilder.insert(selection.active, count.toString())
    })
    count--
})

void editor.edit(editBuilder => {
    // 获取当前编辑器中的多个光标位置
    const selections = editor.selections
    let count = selections.length
    selections.forEach(selection => {
        // 在光标位置插入连续数字
        editBuilder.insert(selection.active, count.toString())
        count--
    })
})

参考自:github.com/microsoft/v…