mirror of
https://github.com/nyanotech/recombobulator
synced 2025-12-16 11:30:21 -08:00
Break out editor interaction into generic function
This commit is contained in:
parent
d3c60af233
commit
a6157d0a16
@ -1,9 +1,10 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('Recombobulator is activated!');
|
||||
function base64(a: string) {
|
||||
return Buffer.from(a).toString('base64'); // TODO - handle different character encodings
|
||||
}
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.base64', () => {
|
||||
function applyEdit(transform: Function) {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
@ -12,12 +13,18 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
editor.edit(editBuilder => {
|
||||
editor.selections.forEach(selection => {
|
||||
const text = document.getText(selection);
|
||||
const processed = Buffer.from(text).toString('base64'); // TODO - handle different character encodings
|
||||
const processed = transform(text);
|
||||
editBuilder.replace(selection, processed);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('Recombobulator is activated!');
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.base64', () => {
|
||||
applyEdit(base64);
|
||||
vscode.window.showInformationMessage('base64-encoded the selection!');
|
||||
}));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user