exceedsystem / vscode-macros

This extension gives the macro features to your vscode.
https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros
MIT License
38 stars 2 forks source link

Can you default the demo macro "TextEditorMacro" in this vscode extension? #2

Open panwanke opened 3 years ago

panwanke commented 3 years ago

On one hand, the "TextEditorMacro" is useful for us. On the other hand, we could learn from it how to code macros.

exceedsystem commented 3 years ago

Tanks for your advice. I'll consider it.

exceedsystem commented 2 years ago

@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"
    }
}

macro_snippets