diff --git a/extension.js b/extension.js index 2944408..9c574e6 100644 --- a/extension.js +++ b/extension.js @@ -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);