当前位置:网站首页>VScode 状态条 StatusBar
VScode 状态条 StatusBar
2022-06-30 16:41:00 【Parzivval】
创建statusBar
// 创建状态条,第一个参数为位置,第二个参数为优先级
myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
// 为状态条注册命令
myStatusBarItem.command = myCommandId;
// 状态条文本显示
myStatusBarItem.text="Nothing is selected!";
// 当鼠标放在上面的时候显示的内容
myStatusBarItem.tooltip="statusBar test!";
// 添加进去
subscriptions.push(myStatusBarItem);
为statusBar创建命令
// 命令名称
const myCommandId = 'sample.showSelectionCount';
// 注册命令
subscriptions.push(vscode.commands.registerCommand(myCommandId, () => {
// 从编辑器获取他所选择的行数
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
// 当点击statusBar时执行的反馈操作:返回选择了多少行
vscode.window.showInformationMessage(`Yeah, ${
n} line(s) selected... Keep going!`);
}));
相关的功能函数
// 实时更新函数
function updateStatusBarItem(): void {
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
if (n > 0) {
myStatusBarItem.text = `$(megaphone) ${
n} line(s) selected`;
// 当有所选择时显示状态条
myStatusBarItem.show();
} else {
// 当未选择时隐藏状态条
myStatusBarItem.hide();
}
}
// 获取选择条数函数
function getNumberOfSelectedLines(editor: vscode.TextEditor | undefined): number {
let lines = 0;
if (editor) {
lines = editor.selections.reduce((prev: number, curr: {
end: {
line: number; }; start: {
line: number; }; }) => prev + (curr.end.line - curr.start.line), 0);
}
return lines;
}
在activate函数里运行实时更新函数
export function activate({
subscriptions }: vscode.ExtensionContext) {
// 命令名称
const myCommandId = 'sample.showSelectionCount';
// 注册命令
subscriptions.push(vscode.commands.registerCommand(myCommandId, () => {
// 从编辑器获取他所选择的行数
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
// 当点击statusBar时执行的反馈操作:返回选择了多少行
vscode.window.showInformationMessage(`Yeah, ${
n} line(s) selected... Keep going!`);
}));
// 创建状态条,第一个参数为位置,第二个参数为优先级
myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
// 为状态条注册命令
myStatusBarItem.command = myCommandId;
// 状态条文本显示
myStatusBarItem.text="Nothing is selected!";
// 当鼠标放在上面的时候显示的内容
myStatusBarItem.tooltip="statusBar test!";
// 添加进去
subscriptions.push(myStatusBarItem);
// register some listener that make sure the status bar
// item always up-to-date
subscriptions.push(vscode.window.onDidChangeActiveTextEditor(updateStatusBarItem));
subscriptions.push(vscode.window.onDidChangeTextEditorSelection(updateStatusBarItem));
// update status bar item once at start
updateStatusBarItem();
}
边栏推荐
- Advanced Mathematics (Seventh Edition) Tongji University General exercises one person solution
- Switching routing (VLAN) experiment
- Php8.0 environment detailed installation tutorial
- Redis (VII) - sentry
- MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
- 2022上半年盘点:20+主流数据库重大更新及技术要点汇总
- K-line diagram interpretation and practical application skills (see position entry)
- Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
- Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides
- Key to understanding the trend of spot Silver
猜你喜欢

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

Development: how to install offline MySQL in Linux system?

Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides

Develop those things: how to add text watermarks to videos?

Analysis on the construction scheme and necessity of constructing expressway video monitoring platform

TFTP下载kernel,nfs挂载文件系统

Importing alicloud ECS locally to solve deployment problems

Radio and television 5g officially set sail, attracting attention on how to apply the golden band

Thinking on large file processing (upload, download)

Switching routing (VLAN) experiment
随机推荐
Development: how to install offline MySQL in Linux system?
Optimization of interface display for general kernel upgrade of mobo video management system v3.5.0
MySQL reports that the column timestamp field cannot be null
Design and principle of tubes responsive data system
Canvas mouse control gravity JS effect
Development details of NFT casting trading platform
5g has been in business for three years. Where will innovation go in the future?
Add code block in word (Reprint)
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
Importing alicloud ECS locally to solve deployment problems
【剑指Offer】53 - I. 在排序数组中查找数字 I
基于SSH的通讯网络电子计费系统
Conception d'un centre commercial en ligne basé sur SSH
每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
Advanced Mathematics (Seventh Edition) Tongji University General exercises one person solution
[binary tree] preorder traversal to construct binary search tree
Analysis on the construction scheme and necessity of constructing expressway video monitoring platform
6 張圖帶你搞懂 TCP 為什麼是三次握手?
What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)