当前位置:网站首页>Vscode status bar statusbar
Vscode status bar statusbar
2022-06-30 18:14:00 【Parzivval】
establish statusBar
// Create a status bar , The first parameter is position , The second parameter is priority
myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
// Register commands for the status bar
myStatusBarItem.command = myCommandId;
// Status bar text display
myStatusBarItem.text="Nothing is selected!";
// The content displayed when the mouse is placed on it
myStatusBarItem.tooltip="statusBar test!";
// Add in
subscriptions.push(myStatusBarItem);
by statusBar Create command
// Command name
const myCommandId = 'sample.showSelectionCount';
// Registration order
subscriptions.push(vscode.commands.registerCommand(myCommandId, () => {
// Get the number of rows selected from the editor
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
// When you click statusBar Feedback operation performed when : Returns the number of rows selected
vscode.window.showInformationMessage(`Yeah, ${
n} line(s) selected... Keep going!`);
}));
Related functions
// Real time update function
function updateStatusBarItem(): void {
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
if (n > 0) {
myStatusBarItem.text = `$(megaphone) ${
n} line(s) selected`;
// Display the status bar when there is a selection
myStatusBarItem.show();
} else {
// Hide the status bar when not selected
myStatusBarItem.hide();
}
}
// Get the selection number function
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;
}
stay activate Function to run the real-time update function
export function activate({
subscriptions }: vscode.ExtensionContext) {
// Command name
const myCommandId = 'sample.showSelectionCount';
// Registration order
subscriptions.push(vscode.commands.registerCommand(myCommandId, () => {
// Get the number of rows selected from the editor
const n = getNumberOfSelectedLines(vscode.window.activeTextEditor);
// When you click statusBar Feedback operation performed when : Returns the number of rows selected
vscode.window.showInformationMessage(`Yeah, ${
n} line(s) selected... Keep going!`);
}));
// Create a status bar , The first parameter is position , The second parameter is priority
myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
// Register commands for the status bar
myStatusBarItem.command = myCommandId;
// Status bar text display
myStatusBarItem.text="Nothing is selected!";
// The content displayed when the mouse is placed on it
myStatusBarItem.tooltip="statusBar test!";
// Add in
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();
}
边栏推荐
- Post penetration file system + uploading and downloading files
- Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
- 【云驻共创】Huawei iConnect使能物联终端一触即联
- 【机器学习】K-means聚类分析
- Deep understanding of JVM (IV) - garbage collection (I)
- Design and principle of tubes responsive data system
- 后渗透之文件系统+上传下载文件
- Small Tools(3) 集成Knife4j3.0.3接口文档
- Animesr: learnable degradation operator and new real world animation VSR dataset
- 墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
猜你喜欢

Dropout: immediate deactivation

MySQL reports that the column timestamp field cannot be null

Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea

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

TCP session hijacking based on hunt1.5

又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队
![[Architecture] 1366- how to draw an excellent architecture diagram](/img/98/5dc29e08e91e751f67d910fadc6430.jpg)
[Architecture] 1366- how to draw an excellent architecture diagram

基于SSH的网上商城设计
![leetcode:787. The cheapest transfer flight in station K [k-step shortest path + DFS memory + defaultdict (dict)]](/img/28/78e2961877776ca3dfcba5ee7e35d2.png)
leetcode:787. The cheapest transfer flight in station K [k-step shortest path + DFS memory + defaultdict (dict)]

5g has been in business for three years. Where will innovation go in the future?
随机推荐
NFT: 开启加密艺术时代的无限可能
Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
Redis (IX) - enterprise level solution (II)
Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides
Deep understanding of JVM (I) - memory structure (I)
MySQL advanced - index optimization (super detailed)
Oneortwo bugs in "software testing" are small things, but security vulnerabilities are big things. We must pay attention to them
分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)
K-line diagram must be read for quick start
MSF后渗透总结
The gates of Europe
如何写一个技术方案
How to write a technical proposal
Fragmentary knowledge points of MySQL
Grep output with multiple colors- Grep output with multiple Colors?
MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc
Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
Compile and generate busybox file system
巴比特 | 元宇宙每日必读:未成年人打赏后要求退款,虚拟主播称自己是大冤种,怎么看待这个监管漏洞?...
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact