mirror of
https://github.com/jasonwilliams/vscode-helix.git
synced 2024-08-17 04:10:46 +03:00
increment / decrement
This commit is contained in:
parent
4ec1caf239
commit
79195ce1b4
12
package.json
12
package.json
@ -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": {
|
||||
|
@ -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());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user