From 5e3927eda14188d59fec0dcd783f005daac6398e Mon Sep 17 00:00:00 2001 From: serg3295 Date: Fri, 22 Dec 2023 09:58:08 +0300 Subject: [PATCH] feat: add setting for specifying characters to jump to --- CHANGELOG.md | 4 ++++ README.md | 12 ++++++++---- package.json | 12 ++++++++++++ src/extension.ts | 5 +++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c1689..24f4bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the "hop-brackets" extension will be documented in this f Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +### 0.1.0 [2023-12-22] + +- New setting `hop-brackets.symbolsUsed` that specifies characters to jump to. + ### 0.0.1 [2023-12-21] - Initial release diff --git a/README.md b/README.md index 065003a..cb7209e 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,24 @@ -A Visual Studio code extension that allows you to easily navigate between the nearest brackets and quotation marks in the source code. +A Visual Studio code extension that allows you to easily navigate between the **nearest** brackets and quotation marks in the source code. -This extension is highly inspired by [jump-brackets](https://github.com/syovchev/jump-brackets). +The built-in VS Code command `editor.action.jumpToBracket` moves the cursor to the closest enclosing bracket when not on a bracket character. This extension adds the feature of moving the cursor to the *nearest* bracket. -Main differences to the "jump-brackets" extension: +The extension is highly inspired by [jump-brackets](https://github.com/syovchev/jump-brackets) extension. Main differences to the *jump-brackets*: - Heavily refactored - Fixed bugs - Removed selection feature -## Usage +## Commands - `hop-brackets.forward` Go to next bracket or quotes. - `hop-brackets.backwards` Go to previous bracket or quotes. ℹ️ No default keybindings are provided by this extension - you'll have to bind the commands yourself. +## Settings + +- `hop-brackets.symbolsUsed` Specifies the characters to jump to. Default value: (){}[]'\" + ## Requirements VS Code version >= 1.75.0 diff --git a/package.json b/package.json index cb41449..876ff96 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,18 @@ "extension": "./out/extension.js" }, "contributes": { + "configuration":[ + { + "title": "HoptoBrackets", + "properties": { + "hop-brackets.symbolsUsed": { + "type": "string", + "default": "(){}[]'\"", + "description": "Specifies the characters to jump to." + } + } + } + ], "commands": [ { "command": "hop-brackets.forward", diff --git a/src/extension.ts b/src/extension.ts index 10bea6a..7ffff4e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,9 +1,8 @@ -import { ExtensionContext, Position, Selection, TextDocument, TextEditor, commands, window } from "vscode" +import { ExtensionContext, Position, Selection, TextDocument, TextEditor, commands, window, workspace } from "vscode" type FinderFunc = (currentPosition: Position, lineContent: string, document: TextDocument) => Position export function activate(context: ExtensionContext): void { - const targets = ["(", ")", "{", "}", "[", "]", '"', "'"] const findBracketForward = ({ line, character }: Position, lineContent: string, document: TextDocument): Position => { let lineNumber = line @@ -71,6 +70,8 @@ export function activate(context: ExtensionContext): void { editor.revealRange(document.lineAt(bracketPosition).range) } + const targets = workspace.getConfiguration().get("hop-brackets.symbolsUsed", "(){}[]'\"").split("") + context.subscriptions.push(commands.registerCommand("hop-brackets.forward", () => hop(findBracketForward))) context.subscriptions.push(commands.registerCommand("hop-brackets.backwards", () => hop(findBracketBackwards))) }