Skip to content

Commit

Permalink
Refacor: change labels and extract fct
Browse files Browse the repository at this point in the history
  • Loading branch information
Fcmam5 committed Jun 20, 2024
1 parent 11c2f6f commit f4a1539
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"commands": [
{
"command": "nimiro.formatNumber",
"title": "Nimiro: Format"
"title": "Nimiro: Enter number to format"
},
{
"command": "nimiro.formatNumberKbd",
"title": "Nimiro format on keybindings pressed"
"title": "Nimiro: format selected number"
}
],
"keybindings": [
Expand All @@ -57,7 +57,7 @@
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.90.0",
"@types/vscode": "^1.0.0",
"@types/mocha": "^10.0.6",
"@types/node": "20.x",
"@typescript-eslint/eslint-plugin": "^7.11.0",
Expand Down
33 changes: 17 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
import * as vscode from "vscode";
import { formatNumberWithSpaces, isNumber } from "./utils";

function showFormattedNumber() {
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
const selection = editor.selection;
const selectedText = document.getText(selection);

if (isNumber(selectedText)) {
vscode.window.showInformationMessage(
formatNumberWithSpaces(selectedText)
);
}
}
}

export function activate(context: vscode.ExtensionContext) {
const cmdWithInput = vscode.commands.registerCommand(
"nimiro.formatNumber",
Expand All @@ -18,24 +33,10 @@ export function activate(context: vscode.ExtensionContext) {

const cmdWithKbd = vscode.commands.registerCommand(
"nimiro.formatNumberKbd",
async () => {
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
const selection = editor.selection;
const selectedText = document.getText(selection);

if (isNumber(selectedText)) {
vscode.window.showInformationMessage(
formatNumberWithSpaces(selectedText)
);
}
}
}
showFormattedNumber
);

context.subscriptions.push(cmdWithInput);
context.subscriptions.push(cmdWithKbd);
context.subscriptions.push(cmdWithKbd, cmdWithInput);
}

// This method is called when your extension is deactivated
Expand Down

0 comments on commit f4a1539

Please sign in to comment.