Closed ralbear closed 5 years ago
Please try this.
"multiCommand.commands": [
{
"command": "multiCommand.createConsoleLog",
"sequence": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "console.log('Console log $1 :', $CLIPBOARD);"
}
}
]
}
]
You can see the specification of code snippets and the variables in https://code.visualstudio.com/docs/editor/userdefinedsnippets
The variable you want to use is $TM_SELECTED_TEXT
.
But the selection is cleared when 'editor.action.insertLineAfter' is executed.
So I propose to copy the selected text to the clipboard by using "editor.action.clipboardCopyAction" first.
Then execute "editor.action.insertLineAfter" and "editor.action.insertSnippet" with the clipboard text referred by $CLIPBOARD
.
@ryuta46 Thanks, that works perfect, i don't have in mind the selection is empty when i change the line.
Im trying to create a simple command to insert a
console.log
with a new line and getting a selected text. The problem i have is the${selectedText}
variable is not working in the script i have insettings.json
settings.json
keybinfings.json
if i have selected a variable, for example
database
and makectrl+shift+l
i get this:Any idea about how to solve this? Thanks in advance!