Skip to content

Commit

Permalink
clipboard support added
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Damasceno committed Apr 6, 2016
1 parent 205c255 commit c529577
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "0.2.0",
"publisher": "fabiodam",
"license": "MIT",
"icon": "",
"engines": {
"vscode": "^0.10.10"
},
Expand All @@ -28,10 +29,10 @@
"url": "https://github.com/fabiodamasceno/vscode-console-wrapper/issues"
},
"homepage": "https://github.com/fabiodamasceno/vscode-console-wrapper/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/fabiodamasceno/vscode-console-wrapper.git"
},
"repository": {
"type": "git",
"url": "https://github.com/fabiodamasceno/vscode-console-wrapper.git"
},
"contributes": {
"commands": [
{
Expand All @@ -54,10 +55,13 @@
"test-local": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --ui tdd ./out/test/extension.test.js"
},
"devDependencies": {
"coveralls": "^2.11.9" ,
"coveralls": "^2.11.9",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"typescript": "^1.8.5",
"vscode": "^0.11.0"
},
"dependencies": {
"copy-paste": "^1.1.4"
}
}
2 changes: 1 addition & 1 deletion src/consoleWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

let ConsoleWrapper = {
wrap : (text: string) => {
return `\n console.log("${text}: ", ${text});`;
return `\n console.log("${text} ", ${text});`;
}
};

Expand Down
29 changes: 19 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
'use strict';

import * as vscode from 'vscode';
import consoleWrapper from './consoleWrapper';
require('copy-paste').global();

export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand("extension.consoleWrapper", () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
var expandedSelection = undefined;

let expandedSelection = undefined;
expandedSelection = getSelection(editor);
if (expandedSelection) {
var text = editor.document.getText(expandedSelection);
let text = editor.document.getText(expandedSelection);
if (text) {
editor.edit((currentText) => {
currentText.insert(new vscode.Position(expandedSelection._end._line, 100000), consoleWrapper.wrap(text));
currentText.insert(new vscode.Position(expandedSelection.end.line, 100000), consoleWrapper.wrap(text));
});
}
}
else
paste((cb, clipboardContent) => {
if (!!clipboardContent) {
let selection = editor.selection;
editor.edit((currentText) => {
currentText.insert(new vscode.Position(selection.active.line, selection.active.character), consoleWrapper.wrap(clipboardContent));
});
}
});
});

context.subscriptions.push(disposable);
Expand All @@ -27,13 +38,11 @@ function getSelection(editor: vscode.TextEditor): vscode.Selection {
const selection = editor.selection;
if (selection.isEmpty) {
const wordRange = editor.document.getWordRangeAtPosition(selection.active);
if (typeof wordRange != 'undefined') {
var expandedSelection = new vscode.Selection(wordRange.start.line, wordRange.start.character, wordRange.end.line, wordRange.end.character);
if (!!wordRange) {
let expandedSelection = new vscode.Selection(wordRange.start.line, wordRange.start.character, wordRange.end.line, wordRange.end.character);
return expandedSelection;
} else {
return undefined;
}
} else {
return selection;
return null;
}
return selection;
}

0 comments on commit c529577

Please sign in to comment.