Last active
July 3, 2022 23:07
-
-
Save exceedsystem/a8ca829f829da90411dac688571325fd to your computer and use it in GitHub Desktop.
An example of 'Insert Random ID' macro for VSCodeMacros extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [VSCode Macros] extension | |
| // https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros | |
| // License:MIT | |
| const vscode = require('vscode'); | |
| module.exports.macroCommands = { | |
| InsertRandomId: { | |
| no: 1, | |
| func: insertRandomId, | |
| }, | |
| }; | |
| function insertRandomId() { | |
| const editor = vscode.window.activeTextEditor; | |
| if (!editor) { | |
| return 'Editor is not opening.'; | |
| } | |
| const rndStr = Math.random().toString(36).slice(-8); | |
| editor.edit((editBuilder) => { | |
| editBuilder.insert(editor.selection.active, rndStr); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment