Open panwanke opened 3 years ago
Tanks for your advice. I'll consider it.
@Asynchro-Epool
I have considered the template feature, but I want to keep this extension as simple as possible. How about registering the following code snippets?
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets
{
"Create new VSCode macro": {
"prefix": "vscmacro",
"body": [
"const vscode = require('vscode');",
"",
"/**",
" * Macro configuration settings",
" * { [name: string]: { ... Name of the macro",
" * no: number, ... Order of the macro",
" * func: ()=> string | undefined ... Name of the body of the macro function",
" * }",
" * }",
" */",
"module.exports.macroCommands = {",
" $1: {",
" no: 1,",
" func: $2,",
" },",
"};",
"",
"/**",
" * Hello world",
" */",
"async function $2() {",
" const editor = vscode.window.activeTextEditor;",
" if (!editor) {",
" // Return an error message if necessary.",
" return 'Active text editor not found.';",
" }",
" const document = editor.document;",
" const selection = editor.selection;",
" const text = document.getText(selection);",
"",
" editor.edit((editBuilder) => {",
" editBuilder.replace(selection, `Hello world! \\${text}`);",
" });",
"}"
],
"description": "VSCodeMacros Template"
}
}
On one hand, the "TextEditorMacro" is useful for us. On the other hand, we could learn from it how to code macros.