当前位置:网站首页>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();
}
边栏推荐
- C语言结构体
- Importing alicloud ECS locally to solve deployment problems
- News management system based on SSM
- Deep understanding of JVM (V) - garbage collection (II)
- 墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
- K-line diagram must be read for quick start
- 分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)
- Do fresh students get a job or choose a job after graduation?
- 报名“互联网+”大赛华为云命题,诸多礼品任你拿!
- Communication network electronic billing system based on SSH
猜你喜欢

Vue3 reactive database

又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队

Redis (IV) - delete policy

What will be the game changes brought about by the meta universe?

零基础也能做Apple大片!这款免费工具帮你渲染、做特效、丝滑展示

腾讯持久化框架MMKV原理探究

Communication network electronic billing system based on SSH

Redis (II) -- persistence

Nft: unlimited possibilities to open the era of encryption Art

Hcip (Huawei Senior Network Security Engineer) (Experiment 8) (MPLS basic experiment)
随机推荐
IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
Deep understanding of JVM (V) - garbage collection (II)
力扣解法汇总1175-质数排列
5g has been in business for three years. Where will innovation go in the future?
What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
Deep understanding of JVM (III) - memory structure (III)
每日面试1题-如何防止CDN防护被绕过
Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)
分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact
Nft: unlimited possibilities to open the era of encryption Art
Animesr: learnable degradation operator and new real world animation VSR dataset
ASP. Net password encryption and password login
Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
[sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence
Flutter custom component
Ten thousand volumes - list sorting [01]
Tubes响应性数据系统的设计与原理
如何写一个技术方案