From b2eb4987896cd70bd594aaed11dd075e463cb2a5 Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Wed, 20 Sep 2017 17:36:13 +0530 Subject: Added context menu and get selected text --- package.json | 82 +++++++++++++++++++++++++++++++++----------------------- src/extension.ts | 16 ++++++++--- 2 files changed, 60 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 7991635..1ff17f0 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,51 @@ { - "name": "kopy-io-plugin", - "displayName": "Kopy.io Plugin", - "description": "An unofficial plugin for kopy.io", - "version": "0.0.1", - "publisher": "indrajithkl", - "engines": { - "vscode": "^1.16.0" - }, - "categories": [ - "Other" + "name": "kopy-io-plugin", + "displayName": "Kopy.io Plugin", + "description": "An unofficial plugin for kopy.io", + "version": "0.0.1", + "publisher": "indrajithkl", + "engines": { + "vscode": "^1.16.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "onCommand:extension.kopyit" + ], + "main": "./out/src/extension", + "contributes": { + "commands": [ + { + "command": "extension.kopyit", + "title": "Kopy.io it." + } ], - "activationEvents": [ - "onCommand:extension.sayHello" - ], - "main": "./out/src/extension", - "contributes": { - "commands": [{ - "command": "extension.sayHello", - "title": "Hello World" - }] - }, - "scripts": { - "vscode:prepublish": "npm run compile", - "compile": "tsc -p ./", - "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "npm run compile && node ./node_modules/vscode/bin/test" - }, - "devDependencies": { - "typescript": "^2.5.2", - "vscode": "^1.1.5", - "mocha": "^3.5.0", - "@types/node": "^7.0.43", - "@types/mocha": "^2.2.42" + "menus": { + "editor/context": [ + { + "when": "editorHasSelection", + "command": "extension.kopyit", + "group": "myGroup@1" + } + ] } -} \ No newline at end of file + }, + "scripts": { + "vscode:prepublish": "npm run compile", + "compile": "tsc -p ./", + "watch": "tsc -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "npm run compile && node ./node_modules/vscode/bin/test" + }, + "devDependencies": { + "typescript": "^2.5.2", + "vscode": "^1.1.5", + "mocha": "^3.5.0", + "@types/node": "^7.0.43", + "@types/mocha": "^2.2.42" + }, + "dependencies": { + "axios": "^0.16.2" + } +} diff --git a/src/extension.ts b/src/extension.ts index 4aa7a1a..f706a2c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; +import * as axios from 'axios'; // this method is called when your extension is activated // your extension is activated the very first time the command is executed @@ -14,14 +15,21 @@ export function activate(context: vscode.ExtensionContext) { // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json - let disposable = vscode.commands.registerCommand('extension.sayHello', () => { - // The code you place here will be executed every time your command is executed + + let olaCommand = vscode.commands.registerCommand('extension.kopyit', (data) => { + // The code you place here will be executed every time your command is executed + const editor = vscode.window.activeTextEditor; + const document = editor.document; + + console.log(editor.selection); + let selectedText = document.getText(new vscode.Range(editor.selection.start, editor.selection.end)); + console.log(selectedText); // Display a message box to the user - vscode.window.showInformationMessage('Hello World!'); + vscode.window.showInformationMessage('Hello Worlds!'); }); - context.subscriptions.push(disposable); + context.subscriptions.push(olaCommand); } // this method is called when your extension is deactivated -- cgit v1.2.3