Skip to content

Instantly share code, notes, and snippets.

@duydao
Created December 28, 2016 00:14
Show Gist options
  • Save duydao/2c0f535ea09189da3fb23ee718acf38f to your computer and use it in GitHub Desktop.
Save duydao/2c0f535ea09189da3fb23ee718acf38f to your computer and use it in GitHub Desktop.
vscode cmd+d plugin
'use strict';
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('extension.sublime.cmd_d', () => {
let editor = vscode.window.activeTextEditor;
if ( !editor ) {
return;
};
let {document, selections} = editor;
if (selections.length === 1 || selections.every(selection => !!!selection.isEmpty)) {
// run default if no empty selections
return vscode.commands.executeCommand("editor.action.addSelectionToNextFindMatch");
}
editor.selections = selections.map(s => {
if (s.isEmpty) {
let { start, end } = document.getWordRangeAtPosition(s.active);
let startPosition = new vscode.Position(start.line, start.character);
let endPosition = new vscode.Position(start.line, end.character);
return new vscode.Selection(startPosition, endPosition);
}
return s;
});
});
context.subscriptions.push(disposable);
}
export function deactivate() {
// nothing here ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment