Skip to content

Commit

Permalink
feat: add setting for specifying characters to jump to
Browse files Browse the repository at this point in the history
  • Loading branch information
serg3295 committed Dec 22, 2023
1 parent 81840e8 commit 5e3927e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))
}
Expand Down

0 comments on commit 5e3927e

Please sign in to comment.