Home > Mobile >  VS Code - Selection to multi cursor
VS Code - Selection to multi cursor

Time:01-06

Does anyone know how to turn an vscode editor selection range into a multi cursor selection?

for instance on this line: "out of this line I'd like to select this|" selection range

  1. run the key bind selection would turn into multi cursor like so "out of this line I'd like to | select this |"

multi cursor selection

CodePudding user response:

You can use the extension convert selection demo

Here is the entire code of the extension:

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;
  •  Tags:  
  • Related