mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
24 lines
676 B
TypeScript
24 lines
676 B
TypeScript
'use strict';
|
|
|
|
import * as vscode from 'vscode';
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
const disposable = vscode.commands.registerCommand('extension.reverseWord', function() {
|
|
// Get the active text editor
|
|
const editor = vscode.window.activeTextEditor;
|
|
|
|
if (editor) {
|
|
const document = editor.document;
|
|
const selection = editor.selection;
|
|
|
|
// Get the word within the selection
|
|
const word = document.getText(selection);
|
|
const reversed = word.split('').reverse().join('');
|
|
editor.edit(editBuilder => {
|
|
editBuilder.replace(selection, reversed);
|
|
});
|
|
}
|
|
});
|
|
|
|
context.subscriptions.push(disposable);
|
|
} |