MVP of a base64-encode command

This commit is contained in:
nyanotech 2022-03-23 10:24:16 +00:00
parent f08e230058
commit 20e5eb7456
Signed by: nyanotech
GPG Key ID: D2D0A9E8F160472B
2 changed files with 20 additions and 23 deletions

View File

@ -10,14 +10,14 @@
"Other"
],
"activationEvents": [
"onCommand:recombobulator.helloWorld"
"onCommand:recombobulator.base64"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "recombobulator.helloWorld",
"title": "Hello World"
"command": "recombobulator.base64",
"title": "base64 encode"
}
]
},

View File

@ -1,26 +1,23 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "recombobulator" is now active!');
console.log('Recombobulator is activated!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('recombobulator.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from recombobulator!');
});
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.base64', () => {
const editor = vscode.window.activeTextEditor;
context.subscriptions.push(disposable);
if (editor) {
const document = editor.document;
const selection = editor.selection;
const text = document.getText(selection);
const processed = Buffer.from(text).toString('base64'); // TODO - handle different character encodings
editor.edit(editBuilder => {
editBuilder.replace(selection, processed);
});
}
vscode.window.showInformationMessage('base64-encoded the selection!');
}));
}
// this method is called when your extension is deactivated
export function deactivate() {}