mirror of
https://github.com/nyanotech/recombobulator
synced 2025-12-16 11:30:21 -08:00
MVP of a base64-encode command
This commit is contained in:
parent
f08e230058
commit
20e5eb7456
@ -10,14 +10,14 @@
|
|||||||
"Other"
|
"Other"
|
||||||
],
|
],
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onCommand:recombobulator.helloWorld"
|
"onCommand:recombobulator.base64"
|
||||||
],
|
],
|
||||||
"main": "./dist/extension.js",
|
"main": "./dist/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "recombobulator.helloWorld",
|
"command": "recombobulator.base64",
|
||||||
"title": "Hello World"
|
"title": "base64 encode"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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';
|
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) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
console.log('Recombobulator is activated!');
|
||||||
// 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!');
|
|
||||||
|
|
||||||
// The command has been defined in the package.json file
|
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.base64', () => {
|
||||||
// Now provide the implementation of the command with registerCommand
|
const editor = vscode.window.activeTextEditor;
|
||||||
// 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(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() {}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user