Created
December 28, 2016 00:14
-
-
Save duydao/2c0f535ea09189da3fb23ee718acf38f to your computer and use it in GitHub Desktop.
vscode cmd+d plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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