Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added relative go to negative with the minus sign prefilled #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"shortcuts",
"relative",
"goto",
"gotoNegative",
"lines",
"jump"
],
Expand Down
58 changes: 58 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,63 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const registeredCommandGotoNegative = vscode.commands.registerCommand(
"relativity.gotoNegative",
async () => {
// Get the current editor
const editor: vscode.TextEditor | undefined =
vscode.window.activeTextEditor;

// If the current editor is undefined (meaning user focus not on a editor), just ignore the command
if (!editor) return;

// Get input from user
const input: string | undefined = await vscode.window.showInputBox({
value: "-",
prompt: "Jump using relative number of lines",
validateInput: newPeekline(editor),
});
// Delete highlight generated in preview function
deleteHighlight(editor);

// End if input box closed after losing focus or if user pressed esc or if user pressed enter with no input
if (input === undefined || input === "") {
// Replace visible range/viewPort with how it was before the preview
editor.revealRange(
new vscode.Range(editor.selection.active, editor.selection.active),
vscode.TextEditorRevealType.InCenterIfOutsideViewport
);

return;
}

// Get lines to jump and characters to jump from input
const { linesToJump, charactersToJump } = parseInput(input);

// Create the new end position using linesToJump
const newPosition: vscode.Position = createNewPosition(
editor,
linesToJump,
charactersToJump
);

// Create new selection object where the start and end positions are the same, to make it a singular cursor movement
const newSelection: vscode.Selection = new vscode.Selection(
newPosition,
newPosition
);

// Set new selection onto current text editor
editor.selection = newSelection;

// Shifts visible range if needed
shiftVisibleRange(editor, newPosition);
}
);

const registeredCommandSelect = vscode.commands.registerCommand(
"relativity.select",
async () => {
Expand Down Expand Up @@ -130,6 +187,7 @@ export async function activate(context: vscode.ExtensionContext) {
);

context.subscriptions.push(registeredCommandGoto);
context.subscriptions.push(registeredCommandGotoNegative);
context.subscriptions.push(registeredCommandSelect);
}

Expand Down