vscode-macros icon indicating copy to clipboard operation
vscode-macros copied to clipboard

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

Open panwanke opened this issue 3 years ago • 2 comments

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

panwanke avatar Jul 03 '21 04:07 panwanke

Tanks for your advice. I'll consider it.

exceedsystem avatar Jul 03 '21 22:07 exceedsystem

@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

exceedsystem avatar Nov 15 '21 12:11 exceedsystem