当前位置:网站首页>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();
}
边栏推荐
- ASP. Net password encryption and password login
- Ten thousand volumes - list sorting [01]
- Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)
- Ardunio esp32 DH11 real time uploading temperature and humidity Alibaba cloud self built mqtt
- 元宇宙带来的游戏变革会是怎样的?
- TCP session hijacking based on hunt1.5
- Three methods of modifying time zone in MySQL
- The gates of Europe
- Grep output with multiple colors- Grep output with multiple Colors?
- IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
猜你喜欢

Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)

Conception d'un centre commercial en ligne basé sur SSH

Redis (VII) - sentry

Exploration and practice of "flow batch integration" in JD

Deep understanding of JVM (IV) - garbage collection (I)

Vue3 reactive database

NFT: 开启加密艺术时代的无限可能

New research of HKUST & MsrA: about image to image conversion, finishing is all you need

广电5G正式启航,黄金频段将如何应用引关注

Post penetration file system + uploading and downloading files
随机推荐
splitting. JS password display hidden JS effect
Switching routing (VLAN) experiment
Partition marble (multiple knapsack + binary optimization)
The secondary menu of the magic article system v5.4.0 supports the optimization of form display
如何写一个技术方案
5g has been in business for three years. Where will innovation go in the future?
News management system based on SSM
Word中添加代码块(转载)
Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
Ardunio esp32 DH11 real time uploading temperature and humidity Alibaba cloud self built mqtt
Synchronized summary
Tubes响应性数据系统的设计与原理
[binary tree] preorder traversal to construct binary search tree
[sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
Design of online shopping mall based on SSH
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
Develop those things: how to add text watermarks to videos?
K-line diagram interpretation and practical application skills (see position entry)