【发布时间】:2022-01-05 13:52:37
【问题描述】:
【问题讨论】:
标签: visual-studio-code vscode-extensions
【问题讨论】:
标签: visual-studio-code vscode-extensions
您可以使用扩展名Select By v1.10
执行命令:SelectBy:为选择的锚点和活动位置创建单独的光标,selectby.anchorAndActiveSeparate
它将为所有当前选择的每个锚点和活动位置创建新光标。消除了重叠的光标。
【讨论】:
假设您只使用一个选择:
const selection = vscode.window.activeTextEditor.selections[0];
const newSelection1 = new vscode.Selection(selection.start, selection.start);
const newSelection2 = new vscode.Selection(selection.end, selection.end);
vscode.window.activeTextEditor.selections = [newSelection1, newSelection2];
选择从左到右和从右到左会得到相同的结果。
我把它做成了一个扩展:Convert Selection - 它适用于多个选择。
这是扩展的完整代码:
const vscode = require('vscode');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let disposable = vscode.commands.registerCommand('convert-selection.surround', function () {
const editor = vscode.window.activeTextEditor;
const selections = editor.selections;
const newSelections = [];
for (const selection of selections) {
const newSelection1 = new vscode.Selection(selection.start, selection.start);
const newSelection2 = new vscode.Selection(selection.end, selection.end);
newSelections.push(newSelection1, newSelection2);
}
editor.selections = newSelections;
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
【讨论】:
Convert Selection。还没有写自述文件。默认键绑定是Alt+s,命令是convert-selection.surround:Surround selection(s) with multi-cursors。