increment / decrement

This commit is contained in:
jasonwilliams 2024-02-02 00:01:18 +00:00
parent 4ec1caf239
commit 79195ce1b4
3 changed files with 48 additions and 2 deletions

View File

@ -277,7 +277,17 @@
{
"key": "alt+OEM_8",
"command": "extension.helixKeymap.switchToUppercase",
"when": "true"
"when": "(extension.helixKeymap.normalMode || extension.helixKeymap.visualMode)"
},
{
"key": "ctrl+a",
"command": "extension.helixKeymap.increment",
"when": "(extension.helixKeymap.normalMode || extension.helixKeymap.visualMode)"
},
{
"key": "ctrl+x",
"command": "extension.helixKeymap.decrement",
"when": "(extension.helixKeymap.normalMode || extension.helixKeymap.visualMode)"
}
],
"configuration": {

View File

@ -463,3 +463,33 @@ export function switchToUppercase(editor: vscode.TextEditor): void {
});
});
}
export function incremenet(editor: vscode.TextEditor): void {
// Move the cursor to the first number and incremene the number
// If the cursor is not on a number, then do nothing
editor.edit((editBuilder) => {
editor.selections.forEach((selection) => {
const translatedSelection = selection.with(selection.start, selection.start.translate(0, 1));
const text = editor.document.getText(translatedSelection);
const number = parseInt(text, 10);
if (!isNaN(number)) {
editBuilder.replace(translatedSelection, (number + 1).toString());
}
});
});
}
export function decrement(editor: vscode.TextEditor): void {
// Move the cursor to the first number and incremene the number
// If the cursor is not on a number, then do nothing
editor.edit((editBuilder) => {
editor.selections.forEach((selection) => {
const translatedSelection = selection.with(selection.start, selection.start.translate(0, 1));
const text = editor.document.getText(translatedSelection);
const number = parseInt(text, 10);
if (!isNaN(number)) {
editBuilder.replace(translatedSelection, (number - 1).toString());
}
});
});
}

View File

@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { symbolProvider } from './SymbolProvider';
import { switchToUppercase } from './actions/actions';
import { decrement, incremenet, switchToUppercase } from './actions/actions';
import { commandLine } from './commandLine';
import { escapeHandler } from './escape_handler';
import { onDidChangeActiveTextEditor, onDidChangeTextDocument } from './eventHandlers';
@ -91,6 +91,12 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.commands.registerCommand('extension.helixKeymap.switchToUppercase', () => {
switchToUppercase(vscode.window.activeTextEditor!);
}),
vscode.commands.registerCommand('extension.helixKeymap.increment', () => {
incremenet(vscode.window.activeTextEditor!);
}),
vscode.commands.registerCommand('extension.helixKeymap.decrement', () => {
decrement(vscode.window.activeTextEditor!);
}),
);
enterNormalMode(globalhelixState);