From 697317723af30cac364689375c7293a0ded63362 Mon Sep 17 00:00:00 2001 From: Jeffrey Scott French Date: Fri, 30 Mar 2018 16:57:41 -0400 Subject: [PATCH 1/2] Place cursor inside paranthesis when inserting empty console.log() --- extension.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/extension.js b/extension.js index 2944408..bf559bc 100644 --- a/extension.js +++ b/extension.js @@ -55,6 +55,11 @@ function activate(context) { const selection = editor.selection; const text = editor.document.getText(selection); + const placeholder = ""; + const cursorPlacement = () => { + vscode.commands.executeCommand('cursorMove',{to: 'wrappedLineEnd'}); + vscode.commands.executeCommand('cursorMove',{to: 'left', by: 'character', value :2}); + }; text ? vscode.commands.executeCommand('editor.action.insertLineAfter') @@ -62,7 +67,14 @@ function activate(context) { const logToInsert = `console.log('${text}: ', ${text});`; insertText(logToInsert); }) - : insertText('console.log();'); + : vscode.commands.executeCommand('editor.action.insertLineAfter') + .then(() => { + const emptyInsert = `console.log(${placeholder});`; + insertText(emptyInsert); + }) + .then(() => { + cursorPlacement(); + }) }); context.subscriptions.push(insertLogStatement); From b2eb3140ce6d97db298229d572b016ba4d61f0a6 Mon Sep 17 00:00:00 2001 From: Jeffrey Scott French Date: Fri, 27 Apr 2018 10:50:10 -0400 Subject: [PATCH 2/2] Remove new line addition on empty log insert. --- extension.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/extension.js b/extension.js index bf559bc..9c574e6 100644 --- a/extension.js +++ b/extension.js @@ -56,25 +56,22 @@ function activate(context) { const selection = editor.selection; const text = editor.document.getText(selection); const placeholder = ""; + const emptyInsert = `console.log(${placeholder});`; const cursorPlacement = () => { - vscode.commands.executeCommand('cursorMove',{to: 'wrappedLineEnd'}); + // 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); - }) - : vscode.commands.executeCommand('editor.action.insertLineAfter') - .then(() => { - const emptyInsert = `console.log(${placeholder});`; - insertText(emptyInsert); - }) - .then(() => { - cursorPlacement(); - }) + ? vscode.commands.executeCommand('editor.action.insertLineAfter') + .then(() => { + const logToInsert = `console.log('${text}: ', ${text});`; + insertText(logToInsert); + }) + : insertText(emptyInsert); + cursorPlacement(); }); context.subscriptions.push(insertLogStatement);