From 306fb8be361833ef0a4defb8905c5b48a9a8146e Mon Sep 17 00:00:00 2001 From: Arthur Lobo <64273139+ArthurLobopro@users.noreply.github.com> Date: Fri, 10 Nov 2023 00:55:49 -0300 Subject: [PATCH] feat: add snap button on status bar --- package.json | 2 +- src/extension.js | 4 +++- src/statusBarButton.js | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/statusBarButton.js diff --git a/package.json b/package.json index 5f63377..8e085c5 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "Other" ], "activationEvents": [ - "onCommand:codesnap.start" + "*" ], "main": "./src/extension.js", "contributes": { diff --git a/src/extension.js b/src/extension.js index 6f31aa4..c096aa6 100644 --- a/src/extension.js +++ b/src/extension.js @@ -4,6 +4,7 @@ const vscode = require('vscode'); const path = require('path'); const { homedir } = require('os'); const { readHtml, writeFile, getSettings } = require('./util'); +const { createStatusbarButton } = require('./statusBarButton.js'); const getConfig = () => { const editorSettings = getSettings('editor', ['fontLigatures', 'tabSize']); @@ -102,5 +103,6 @@ const runCommand = async (context) => { module.exports.activate = (context) => context.subscriptions.push( - vscode.commands.registerCommand('codesnap.start', () => runCommand(context)) + vscode.commands.registerCommand('codesnap.start', () => runCommand(context)), + createStatusbarButton() ); diff --git a/src/statusBarButton.js b/src/statusBarButton.js new file mode 100644 index 0000000..bef1ca6 --- /dev/null +++ b/src/statusBarButton.js @@ -0,0 +1,25 @@ +'use strict' + +const vscode = require('vscode') + +const createStatusbarButton = () => { + const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 150) + item.text = '$(device-camera)' + item.tooltip = "Snap code" + item.color = 'inherit' + item.command = 'codesnap.start' + + let isVisible = false + + return vscode.window.onDidChangeTextEditorSelection(event => { + if (event.textEditor.selection.isEmpty && isVisible) { + item.hide() + isVisible = false + } else if (!isVisible) { + item.show() + isVisible = true + } + }) +} + +module.exports = { createStatusbarButton }