diff --git a/CHANGELOG.md b/CHANGELOG.md index 133f357..be27442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,14 @@ All notable changes to the "paragraphjump" extension will be documented in this file. -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## 1.0.0 -## [Unreleased] +### Added -- Initial release \ No newline at end of file +- Added support for selecting paragraphs up and down. + +## 0.0.1 + +### Added + +- Initial release with only jump up and down functionality. diff --git a/README.md b/README.md index 84a3477..6cf7f5e 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,42 @@ ParagraphJump allows the user to navigate swiftly between paragraphs. * `paragraphjump.up`: Move up a paragraph * `paragraphjump.down`: Move down a paragraph - -## Extension Settings - -Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. +* `paragraphjump.selectup`: Select one paragraph up +* `paragraphjump.selectdown`: Select one paragraph down + +## Gettings started + +This plugin will automatically be enabled after using one of the commands specified above. + +### Keyboard shortcuts + +To optimally use this plugin it is recommended to re-map your keybindings. You can do this through the **Keyboard Shortcuts** editor available +through the **Preferences** -> **Keyboard Shortcuts** menu. + +My personal bindings for this plugin is displayed below as an example: + +```JSON + { + "key": "ctrl+up", + "command": "paragraphjump.up", + "when": "textInputFocus" + }, + { + "key": "ctrl+down", + "command": "paragraphjump.down", + "when": "textInputFocus" + }, + { + "key": "ctrl+shift+down", + "command": "paragraphjump.selectdown", + "when": "textInputFocus" + }, + { + "key": "ctrl+shift+up", + "command": "paragraphjump.selectup", + "when": "textInputFocus" + } +``` ## Known Issues @@ -17,6 +49,10 @@ None at the time. ## Release Notes +### 1.0.0 + +First full release with all the intended functionality for the plugin. + ### 0.0.1 -Initial release including move up and down features. \ No newline at end of file +Initial release including move up and down features diff --git a/package.json b/package.json index 97aaafa..7b2c518 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "paragraphjump", "displayName": "ParagraphJump", "description": "Allows the user to navigate swiftly between paragraphs", - "version": "0.0.1", + "version": "1.0.0", "publisher": "brokenprogrammer", "repository": { "type": "git", @@ -25,7 +25,9 @@ ], "activationEvents": [ "onCommand:paragraphjump.up", - "onCommand:paragraphjump.down" + "onCommand:paragraphjump.down", + "onCommand:paragraphjump.selectup", + "onCommand:paragraphjump.selectdown" ], "main": "./out/extension.js", "contributes": { @@ -37,6 +39,14 @@ { "command": "paragraphjump.down", "title": "ParagraphJump: Down" + }, + { + "command": "paragraphjump.selectup", + "title": "ParagraphJump: Select Up" + }, + { + "command": "paragraphjump.selectdown", + "title": "ParagraphJump: Select Down" } ] }, diff --git a/src/extension.ts b/src/extension.ts index 3be605b..2411d02 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,15 +1,27 @@ import * as vscode from "vscode"; +enum LineOperation { + up = 0, + down = 1, +} + +enum MoveOperation { + move = 0, + select = 1, +} + +enum ParagraphJumpOperation { + moveUp = 0, + moveDown = 1, + selectUp = 2, + selectDown = 3, +} + const targetLineIsEmptyOrWhitespace = ( line: number, document: vscode.TextDocument ) => !document.lineAt(line).isEmptyOrWhitespace; -enum LineOperation { - up = 1, - down = 2, -} - function getNextLine(editor: vscode.TextEditor, op: LineOperation) { let document = editor.document; let line = editor.selection.active.line; @@ -34,32 +46,99 @@ function getNextLine(editor: vscode.TextEditor, op: LineOperation) { return document.lineAt(line); } -function moveCursor(editor: vscode.TextEditor, newPosition: vscode.Position) { - let newCursorPosition = new vscode.Selection(newPosition, newPosition); +function moveCursor( + editor: vscode.TextEditor, + newPosition: vscode.Position, + op: MoveOperation +) { + let newCursorPosition: vscode.Selection; + switch (op) { + case MoveOperation.move: + { + newCursorPosition = new vscode.Selection(newPosition, newPosition); + } + break; + case MoveOperation.select: + { + const anchor = editor.selection.anchor; + newCursorPosition = new vscode.Selection(anchor, newPosition); + } + break; + } editor.selection = newCursorPosition; editor.revealRange(new vscode.Range(newPosition, newPosition)); } +function performParagraphJumpOperation( + editor: vscode.TextEditor, + op: ParagraphJumpOperation +) { + switch (op) { + case ParagraphJumpOperation.moveUp: + case ParagraphJumpOperation.selectUp: + { + const targetLine = getNextLine(editor, LineOperation.up); + const newPosition = new vscode.Position(targetLine.lineNumber, 0); + const moveOp = + op === ParagraphJumpOperation.moveUp + ? MoveOperation.move + : MoveOperation.select; + moveCursor(editor, newPosition, moveOp); + } + break; + case ParagraphJumpOperation.moveDown: + case ParagraphJumpOperation.selectDown: + { + const targetLine = getNextLine(editor, LineOperation.down); + const newPosition = new vscode.Position( + targetLine.lineNumber, + targetLine.text.length + ); + const moveOp = + op === ParagraphJumpOperation.moveDown + ? MoveOperation.move + : MoveOperation.select; + moveCursor(editor, newPosition, moveOp); + } + break; + } +} + export function activate(context: vscode.ExtensionContext) { let paragraphJumpUp = vscode.commands.registerTextEditorCommand( "paragraphjump.up", (editor: vscode.TextEditor) => { - let targetLine: vscode.TextLine = getNextLine(editor, LineOperation.up); - const newPosition = new vscode.Position(targetLine.lineNumber, 0); - moveCursor(editor, newPosition); + performParagraphJumpOperation(editor, ParagraphJumpOperation.moveUp); } ); let paragraphJumpDown = vscode.commands.registerTextEditorCommand( "paragraphjump.down", (editor: vscode.TextEditor) => { - let targetLine: vscode.TextLine = getNextLine(editor, LineOperation.down); - const newPosition = new vscode.Position(targetLine.lineNumber, 0); - moveCursor(editor, newPosition); + performParagraphJumpOperation(editor, ParagraphJumpOperation.moveDown); } ); - context.subscriptions.push(paragraphJumpUp, paragraphJumpDown); + let paragraphSelectUp = vscode.commands.registerTextEditorCommand( + "paragraphjump.selectup", + (editor: vscode.TextEditor) => { + performParagraphJumpOperation(editor, ParagraphJumpOperation.selectUp); + } + ); + + let paragraphSelectDown = vscode.commands.registerTextEditorCommand( + "paragraphjump.selectdown", + (editor: vscode.TextEditor) => { + performParagraphJumpOperation(editor, ParagraphJumpOperation.selectDown); + } + ); + + context.subscriptions.push( + paragraphJumpUp, + paragraphJumpDown, + paragraphSelectUp, + paragraphSelectDown + ); } export function deactivate() {}