Code Monkey home page Code Monkey logo

vscode-powertools's Introduction

ReadMe

PowerTools目的是扩展VSCode文本处理能力,提供转换大小写、base64编码解码、排序行,哈希文本、自定义扩展指令等功能。

主要功能

自定义扩展指令

文本处理

  • 大小写转换
  • base64编码/解码
  • 移除空行
  • 移除首尾空格
  • 筛选行

行处理

  • 按文本排序行
  • 按数字排序行
  • 翻转行

其他功能

  • 选中文本哈希
  • 生成32位随机串
  • 生成强密码
  • 对选中文本求和
  • 对选中文本取平均数字

演示

功能列表截图

list

大小写转换

toupper

行排序

sort

base64编码

base64

求和

sum

翻转行

reverse

Custom Command

插件支持用户通过加载外部js文件来达到扩展功能的目的。对于有自定义扩展需求的用户,可以参照以下步骤来实现。

一.编写js文件

在本地新建一个js文件,复制以下内容:

module.exports.custom_toupper = async function(context) {
    var text = context.getText();
    await context.setText(text.toUpperCase());
}

这段代码的作用是导出一个名字为custom_toupper的自定义指令,这个指令的作用是将选中文本转成大写。

现在我们看看函数的实现,可以注意到函数有一个context参数,插件会在运行时把当前上下文对象注入到该参数。context暴露了以下方法供用户使用:

function getText(): string;

获取选中文本

function setText(text: string): Promise<void>;

将当前选中内容设置为指定文本

function require(module: string): any;

用于加载外部模块

var vscode = context.require('vscode');

PS: 对于大部分情况,vscode模块将会是最常使用的,相关vscode-api请点击这里查看。

function getEditor(): vscode.TextEditor;

获取当前要执行指令的编辑器

var editor = context.getEditor();

function getProcessSelection(): vscode.Range;

获取当前待处理区域。请注意以下两点:

  • 当没有选择任何文本时,会选择整个文档内容
  • 当选择了多个区域,会返回第一个 以下代码会打印当前选择文本:
var editor = context.getEditor();
var selection = context.getProcessSelection();
var text = editor.document.getText(selection);
context.print(text);

public async edit(changes: [vscode.Range, string][]): Promise<boolean>;

更新指定区域文本,支持一次更改多个,在一个事务操作中完成。 例如以下代码将每行第一个字符转成大写:

module.exports.toUpper = async function (context) {
    var vscode = context.require('vscode');
    var editor = context.getEditor();
    var changes = new Array();
    var document = editor.document;
    for (var index = 0; index < document.lineCount; index++) {
        var line = document.lineAt(index);
        if (line.isEmptyOrWhitespace) {
            continue;
        }
        var range = line.range.with(new vscode.Position(line.lineNumber, 0), new vscode.Position(line.lineNumber, 1));
        var changeText = document.getText(range).toUpperCase();
        changes.push([range, changeText]);
    }
    await context.edit(changes);
}

public isColumnBlock(): boolean;

判断当前选择内容是否列模式

 var columnBlock = context.isColumnBlock();
 context.print(columnBlock);

public print(): void;

打印文本

二.配置指令文件路径

1)通过文件菜单 -> 首选项 -> 设置 -> 扩展 -> PowerTools,然后点击在setting.json中编辑
2)在配置文件末尾加上以下节点:
"powertools.CommandFiles": []
  • 支持配置多个
  • 支持配置文件夹,当路径时文件夹时,自动加载该文件夹下所有js文件

Release Notes

1.0.5

添加项目git地址

1.0.4

错误修复

1.0.2

自定义指令新增支持getText和setText方法方便快速修改文本

1.0.1

支持用户自定义扩展指令

1.0.0

Initial release

Enjoy!

vscode-powertools's People

Contributors

yanzf0417 avatar

Stargazers

hbybyyang avatar 老董 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

lisiyizu

vscode-powertools's Issues

Add Group in context menu ( There are other extensions implemented.)

image

我之前在 v 站提过,当时回复是 vscode 么有相应 Api 来实现。
今天惊喜的发现有插件做到了 不知道是不是 vscode 新增了 Api

给 lz 参考~ 可以的话弄个分组吧。 装完这个插件 右键要爆炸了。。。

https://github.com/alefragnani/vscode-bookmarks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.