Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ function activate(context) {

const selection = editor.selection;
const text = editor.document.getText(selection);
const placeholder = "";
const emptyInsert = `console.log(${placeholder});`;
const cursorPlacement = () => {
// release the selection caused by inserting
vscode.commands.executeCommand('cursorMove',{to: 'right', by:'character', value :1});
// position the cursor inside the parenthesis
vscode.commands.executeCommand('cursorMove',{to: 'left', by: 'character', value :2});
};

text
? vscode.commands.executeCommand('editor.action.insertLineAfter')
.then(() => {
const logToInsert = `console.log('${text}: ', ${text});`;
insertText(logToInsert);
})
: insertText('console.log();');
? vscode.commands.executeCommand('editor.action.insertLineAfter')
.then(() => {
const logToInsert = `console.log('${text}: ', ${text});`;
insertText(logToInsert);
})
: insertText(emptyInsert);
cursorPlacement();

});
context.subscriptions.push(insertLogStatement);
Expand Down